Realtime Compositor: Implement Inpaint node #111792

Merged
Omar Emara merged 6 commits from OmarEmaraDev/blender:gpu-inpaint into main 2023-09-25 08:45:54 +02:00
Member

This patch implements the Inpaint node for the Realtime Compositor. The
inpainting region is filled by sampling the closest pixel at the inpainting
boundary, which is done using the Jump Flooding algorithm. To smooth the
inpainting region, a lateral blur is applied in the direction tangent to the
inpainting boundary.

The implementation is not identical to the existing CPU implementation due to
technical infeasibility. In particular, the CPU implementation uses a Manhattan
distance transform, while the GPU implementation uses an Euclidean one, which is
a consequence of the use of the Jump Flooding algorithm. Furthermore, the CPU
uses a serial convolution starting from the boundary outwards, while the GPU
uses a lateral Gaussian blur in the direction tangent to the boundary.

Depends on #112223. For the Jump Flooding implementation.

This patch implements the Inpaint node for the Realtime Compositor. The inpainting region is filled by sampling the closest pixel at the inpainting boundary, which is done using the Jump Flooding algorithm. To smooth the inpainting region, a lateral blur is applied in the direction tangent to the inpainting boundary. The implementation is not identical to the existing CPU implementation due to technical infeasibility. In particular, the CPU implementation uses a Manhattan distance transform, while the GPU implementation uses an Euclidean one, which is a consequence of the use of the Jump Flooding algorithm. Furthermore, the CPU uses a serial convolution starting from the boundary outwards, while the GPU uses a lateral Gaussian blur in the direction tangent to the boundary. Depends on #112223. For the Jump Flooding implementation.
Omar Emara added 1 commit 2023-09-01 16:36:10 +02:00
604ba2871a Realtime Compositor: Implement Inpaint node
This patch implements the Inpaint node for the Realtime Compositor.
Omar Emara added 2 commits 2023-09-12 10:55:16 +02:00
Omar Emara changed title from WIP: Realtime Compositor: Implement Inpaint node to Realtime Compositor: Implement Inpaint node 2023-09-12 11:10:53 +02:00
Author
Member

Comparison between CPU and GPU implementations with a 30px inpainting distance. The weird shape of the CPU one is due to the use of Manhatten distance.

CPUvsGPU.png

Comparison between CPU and GPU implementations with a 30px inpainting distance. The weird shape of the CPU one is due to the use of Manhatten distance. ![CPUvsGPU.png](/attachments/9aa3140c-5498-47c8-8e03-0458d9d8daff)
Omar Emara requested review from Clément Foucault 2023-09-12 11:24:32 +02:00
Omar Emara requested review from Sergey Sharybin 2023-09-12 11:24:40 +02:00

Looks very good and super useful! I was just wondering if the left tearing artifact is to be expected image

Looks very good and super useful! I was just wondering if the left tearing artifact is to be expected ![image](/attachments/6a2f403c-dee8-42c1-9eb2-30bac3ee99ee)
Clément Foucault requested changes 2023-09-12 13:03:08 +02:00
@ -0,0 +48,4 @@
if (squared_distance < minimum_squared_distance) {
minimum_squared_distance = squared_distance;
closest_seed_position = position;

Fails on OSX

ERROR (gpu.shader): compositor_jump_flooding Compute Shader: 
      | 
      | Error: assigning to 'vec2' (aka 'float2') from incompatible type 'ivec2' (aka 'int2')
      | 
      | closest_seed_position = position;
      | ^~~~~~~~
Fails on OSX ``` ERROR (gpu.shader): compositor_jump_flooding Compute Shader: | | Error: assigning to 'vec2' (aka 'float2') from incompatible type 'ivec2' (aka 'int2') | | closest_seed_position = position; | ^~~~~~~~ ```
Omar Emara added 1 commit 2023-09-12 13:12:12 +02:00
Author
Member

@fclem Not sure, looking into it.

@fclem Not sure, looking into it.
Author
Member

Apparently, those banding effects are due to a sudden change of the tangent vector because two neighbouring pixels picks up two boundary pixels that are far way from each other, which in this case happens due to the aliasing at the cube edges, as can be seen in this illustration.

20230912-152854.png

A possible workaround is to recompute the tangent at each integration step, at the cost of many more texture fetches, I could look into that.

Apparently, those banding effects are due to a sudden change of the tangent vector because two neighbouring pixels picks up two boundary pixels that are far way from each other, which in this case happens due to the aliasing at the cube edges, as can be seen in this illustration. ![20230912-152854.png](/attachments/21d04882-3e33-4fc2-8f57-f311a9faa282) A possible workaround is to recompute the tangent at each integration step, at the cost of many more texture fetches, I could look into that.
Omar Emara added 1 commit 2023-09-13 09:12:51 +02:00
Omar Emara requested review from Clément Foucault 2023-09-13 09:14:39 +02:00
Clément Foucault approved these changes 2023-09-14 11:45:12 +02:00
Clément Foucault left a comment
Member

The step artifact are indeed fixed! To me everything is good.

The step artifact are indeed fixed! To me everything is good.
Sergey Sharybin approved these changes 2023-09-18 22:37:53 +02:00
Sergey Sharybin left a comment
Owner

I think the difference in the algorithm is fine for the main purpose of the node. I don't think it was really designed to close large gaps.
That being said, do you think it feasible to use euclidean distance on CPU to align its result more closely to GPU?

I think the difference in the algorithm is fine for the main purpose of the node. I don't think it was really designed to close large gaps. That being said, do you think it feasible to use euclidean distance on CPU to align its result more closely to GPU?
Author
Member

@Sergey It is feasible to use euclidean distance for the CPU as well. I just haven't done my homework yet on what the best way to do that is. The 1+JFA algorithm we use on the GPU was chosen because it works well on massively parallel hardware, which might not be the best on CPUs.

@Sergey It is feasible to use euclidean distance for the CPU as well. I just haven't done my homework yet on what the best way to do that is. The 1+JFA algorithm we use on the GPU was chosen because it works well on massively parallel hardware, which might not be the best on CPUs.

@OmarEmaraDev I see. Well, for the main intended use-case I think the difference will be minimal. So don't think it is practical to consider the difference a stopper here.

@OmarEmaraDev I see. Well, for the main intended use-case I think the difference will be minimal. So don't think it is practical to consider the difference a stopper here.
Omar Emara added 1 commit 2023-09-25 08:39:34 +02:00
Omar Emara merged commit acb88528a5 into main 2023-09-25 08:45:54 +02:00
Omar Emara deleted branch gpu-inpaint 2023-09-25 08:45:56 +02:00
Sign in to join this conversation.
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
3 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#111792
No description provided.