Realtime Compositor: Rewrite inpaint node #114849

Merged
Omar Emara merged 5 commits from OmarEmaraDev/blender:refactor-inpaint-node into main 2023-11-22 13:23:11 +01:00
Member

This patch rewrites the Inpaint node in the Realtime Compositor. The old
method suffered from discontinuities and singularities in the inpainting
regions. Furthermore, it ignored semi-transparent areas.

The new method is inspired by a two pass method described by the paper:

Rosner, Jakub, et al. "Fast GPU-based image warping and inpainting for
frame interpolation." International Conferences on Computer Graphics,
Vision and Mathematics. 2010.

In particular, we first fill the inpainting region using jump flooding,
then we apply a variable size blur pass whose size is proportional to
the distance to the inpainting boundary. The smoothed region is then
mixed with the input using its alpha.

The new method is much closer to the Bertalmio-style diffusion-based
inpainting methods, and thus can more accurately close holes than
existing methods.

The aforementioned method requires variable size blur, which is quite
expensive for this use case, so a new implementation was added that
approximates the method using a separable implementation, which provides
a visually pleasing result assuming a sufficiently smooth radius field,
which is true for our case since the field is an SDF.

Fixes: #114422

This patch rewrites the Inpaint node in the Realtime Compositor. The old method suffered from discontinuities and singularities in the inpainting regions. Furthermore, it ignored semi-transparent areas. The new method is inspired by a two pass method described by the paper: Rosner, Jakub, et al. "Fast GPU-based image warping and inpainting for frame interpolation." International Conferences on Computer Graphics, Vision and Mathematics. 2010. In particular, we first fill the inpainting region using jump flooding, then we apply a variable size blur pass whose size is proportional to the distance to the inpainting boundary. The smoothed region is then mixed with the input using its alpha. The new method is much closer to the Bertalmio-style diffusion-based inpainting methods, and thus can more accurately close holes than existing methods. The aforementioned method requires variable size blur, which is quite expensive for this use case, so a new implementation was added that approximates the method using a separable implementation, which provides a visually pleasing result assuming a sufficiently smooth radius field, which is true for our case since the field is an SDF. Fixes: #114422
Omar Emara added the
Interest
Compositing
Module
VFX & Video
labels 2023-11-14 16:12:12 +01:00
Omar Emara added 1 commit 2023-11-14 16:12:29 +01:00
7966137b3e Realtime Compositor: Rewrite inpaint node
This patch rewrites the Inpaint node in the Realtime Compositor. The old
method suffered from discontinuities and singularities in the inpainting
regions. Furthermore, it ignored semi-transparent areas.

The new method is inspired by a two pass method described by the paper:

  Rosner, Jakub, et al. "Fast GPU-based image warping and inpainting for
  frame interpolation." International Conferences on Computer Graphics,
  Vision and Mathematics. 2010.

In particular, we first fill the inpainting region using jump flooding,
then we apply a variable size blur pass whose size is proportional to
the distance to the inpainting boundary. The smoothed region is then
mixed with the input using its alpha.

The aforementioned method requires variable size blur, which is quite
expensive for this use case, so a new implementation was added that
approximates the method using a separable implementation, which provides
a visually pleasing result assuming a sufficiently smooth radius field,
which is true for our case since the field is an SDF.

Fixes: #114422
Author
Member

Comparing CPU and GPU implementation on external inpainting:

20231114-162708.png

Comparing CPU and GPU implementation on internal inpainting:

20231114-162632.png

The file originally shared by Clement in the new implementation:

20231114-163551.png

The file originally shared by Clement in the old implementation:

image

Comparing CPU and GPU implementation on external inpainting: ![20231114-162708.png](/attachments/61978653-177a-4386-b45b-3082a2257427) Comparing CPU and GPU implementation on internal inpainting: ![20231114-162632.png](/attachments/b040c14c-4352-4f1f-9847-696ecf2e6d83) The file originally shared by Clement in the new implementation: ![20231114-163551.png](/attachments/8a3d5ebc-7298-42b7-a083-b5e6b8046bd4) The file originally shared by Clement in the old implementation: ![image](/attachments/6a2f403c-dee8-42c1-9eb2-30bac3ee99ee)
Omar Emara requested review from Sergey Sharybin 2023-11-14 16:28:25 +01:00
Sergey Sharybin approved these changes 2023-11-20 15:50:01 +01:00
Sergey Sharybin left a comment
Owner

This is a nice improvement!

I am not sure what we'll need to do to align CPU and GPU even better, but that's a separate discussion.

Please check on the inlined comment in the shader. Without that weak Blender aborts on macOS. If the suggested fix looks good to you apply it and land (no need in extra review iteration).

This is a nice improvement! I am not sure what we'll need to do to align CPU and GPU even better, but that's a separate discussion. Please check on the inlined comment in the shader. Without that weak Blender aborts on macOS. If the suggested fix looks good to you apply it and land (no need in extra review iteration).
@ -0,0 +36,4 @@
* inpainting distance. Additionally, we clamp to the distance to the inpainting distance since
* areas outside of the clamp range only indirectly affect the inpainting region due to blurring
* and thus needn't use higher blur radii. */
float blur_window_size = min(max_distance, distance_to_boundary) / M_SQRT2;

float blur_window_size = min(float(max_distance), distance_to_boundary) / M_SQRT2;

Otherwise on Metal it gives Error: call to 'min' is ambiguous

`float blur_window_size = min(float(max_distance), distance_to_boundary) / M_SQRT2;` Otherwise on Metal it gives `Error: call to 'min' is ambiguous`
OmarEmaraDev marked this conversation as resolved
Omar Emara added 4 commits 2023-11-22 13:21:42 +01:00
Omar Emara merged commit 48d7d60c96 into main 2023-11-22 13:23:11 +01:00
Omar Emara deleted branch refactor-inpaint-node 2023-11-22 13:23:12 +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#114849
No description provided.