Realtime Compositor: Improve classic Kuwahara precision #114191

Closed
Omar Emara wants to merge 2 commits from OmarEmaraDev/blender:improve-sat-precision into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

This patch improves the precision of the classic Kuwahara operation by
allowing more precise sum evaluation of summed area tables.

The improved precision is achieved by delaying the block completion pass
of the algorithm which implements equation (41) to evaluation time, and
separating the SAT evaluation into an inter-block prologue sum values
and intra-block values. The inter-block values are typically very large,
while the intra-block values are much smaller, so the idea is to compute
the SAT sum on the inter-block and intra-block values separately, then
sum them at the end.

This is of course more expensive and more memory intensive to compute
due to duplicate work at evaluation time and more textures fetches.

The precision is about 10x better in a mean square error sense, at the
const of 20% reduction in performance. While the improved precision is
measurably and visually better, the results are still not really usable
due to the artifacts. So this is more of an infeasibility proof of
concept rather than an actual patch.

This patch improves the precision of the classic Kuwahara operation by allowing more precise sum evaluation of summed area tables. The improved precision is achieved by delaying the block completion pass of the algorithm which implements equation (41) to evaluation time, and separating the SAT evaluation into an inter-block prologue sum values and intra-block values. The inter-block values are typically very large, while the intra-block values are much smaller, so the idea is to compute the SAT sum on the inter-block and intra-block values separately, then sum them at the end. This is of course more expensive and more memory intensive to compute due to duplicate work at evaluation time and more textures fetches. The precision is about 10x better in a mean square error sense, at the const of 20% reduction in performance. While the improved precision is measurably and visually better, the results are still not really usable due to the artifacts. So this is more of an infeasibility proof of concept rather than an actual patch.
Omar Emara added the
Interest
Compositing
Module
VFX & Video
labels 2023-10-27 11:34:55 +02:00
Omar Emara added 1 commit 2023-10-27 11:35:10 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
40ce14fc69
Realtime Compositor: Improve classic Kuwahara precision
This patch improves the precision of the classic Kuwahara operation by
allowing more precise sum evaluation of summed area tables.

The improved precision is achieved by delaying the block completion pass
of the algorithm which implements equation (41) to evaluation time, and
separating the SAT evaluation into an inter-block prologue sum values
and intra-block values. The inter-block values are typically very large,
while the intra-block values are much smaller, so the idea is to compute
the SAT sum on the inter-block and intra-block values separately, then
sum them at the end.

This is of course more expensive and more memory intensive to compute
due to duplicate work at evaluation time and more textures fetches.

While the improved precision is measurably and visually better, the
results are still not really usable due to the artifacts. So this is
more of an infeasibility proof of concept rather than an actual patch.
Author
Member

The patch still needs to be cleaned up and documented. But I suspect we will opt to not apply it.

Using the test file from #113578. Here is a comparison between the existing algorithm and the new algorithm. As can be seen, the artifacts still exist, but are less prominent.

20231027-110013.png

20231027-110007.png

So it appears to me that solving the precision issue is impossible, and our attempts would just move the bar of what is acceptable at the cost of performance. The user will just increase the emission strength and we will be back to square one.

There is a patent algorithm called SAT RipMaps that also tries to improve precision, also by a factor of 10, though with a significant performance implication.

The only solution would be to either clamp the input, document this limitation and optionally let the user clamp the input, or just use a direct convolution as for low radii; potentially as an option.

The patch still needs to be cleaned up and documented. But I suspect we will opt to not apply it. Using the test file from #113578. Here is a comparison between the existing algorithm and the new algorithm. As can be seen, the artifacts still exist, but are less prominent. ![20231027-110013.png](/attachments/3cccb6cb-5e4e-42d9-8be0-3c0b77f3396a) ![20231027-110007.png](/attachments/3c7738bd-4a70-4f2c-81d7-03386d490b19) So it appears to me that solving the precision issue is impossible, and our attempts would just move the bar of what is acceptable at the cost of performance. The user will just increase the emission strength and we will be back to square one. There is a [patent algorithm](https://patents.google.com/patent/US20140185951A1/en) called SAT RipMaps that also tries to improve precision, also by a factor of 10, though with a significant performance implication. The only solution would be to either clamp the input, document this limitation and optionally let the user clamp the input, or just use a direct convolution as for low radii; potentially as an option.
Member

I ran a few tests

  1. import 3000 x 5100 image, render (F12):
    • visually I can't see any difference. Dividing the two images shows a maximum deviation of 20% around upper right edges.
    • run time is around 10% slower (0.70 vs. 0.62s). However, GPU rendering has a higher variation of render time on my machine. When I repeat tests enough times, both master and this patch converge to around 0.5s.
    • In this case I would say the slowdown is not significant, but the improvement is not visible either.
  2. import 3000 x 5100 image, multiply pixel values by 200, apply kuwahara filter, normalize and then render (F12):
    • same results as above.
  3. Using the Viewport I can also reproduce the artefacts using the test file from #113578.
    • I didn't measure times there but I didn't notice any significant slowdown by dragging the viewport around.
    • The patch does improve the results visibly, especially around low strengths (<10).

I don't know if case 3) is a typical scene. If so, then for me it's worth the 80-100ms slowdown (actual slowdown is probably lower when using a proper dedicated GPU and scene has <<4k resolution).

I ran a few tests 1) import 3000 x 5100 image, render (F12): * visually I can't see any difference. Dividing the two images shows a maximum deviation of 20% around upper right edges. * run time is around 10% slower (0.70 vs. 0.62s). However, GPU rendering has a higher variation of render time on my machine. When I repeat tests enough times, both master and this patch converge to around 0.5s. * In this case I would say the slowdown is not significant, but the improvement is not visible either. 2) import 3000 x 5100 image, multiply pixel values by 200, apply kuwahara filter, normalize and then render (F12): * same results as above. 3) Using the Viewport I can also reproduce the artefacts using the test file from #113578. * I didn't measure times there but I didn't notice any significant slowdown by dragging the viewport around. * The patch does improve the results visibly, especially around low strengths (<10). I don't know if case 3) is a typical scene. If so, then for me it's worth the 80-100ms slowdown (actual slowdown is probably lower when using a proper dedicated GPU and scene has <<4k resolution).
Author
Member

@blender-bot package

@blender-bot package
Member

Package build started. Download here when ready.

Package build started. [Download here](https://builder.blender.org/download/patch/PR114191) when ready.
Omar Emara added 1 commit 2023-11-17 10:27:05 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
6876d00752
Merge branch 'main' into improve-sat-precision
Author
Member

@blender-bot package

@blender-bot package
Member

Package build started. Download here when ready.

Package build started. [Download here](https://builder.blender.org/download/patch/PR114191) when ready.
Author
Member

It was decided that the improved precision is not worth it relative to the performance hit, especially since the artifacts still persist even with the improved precision. So this will be abandoned, and might be vinisted later if SAT is used in other places that might benefit from this improvement.

It was decided that the improved precision is not worth it relative to the performance hit, especially since the artifacts still persist even with the improved precision. So this will be abandoned, and might be vinisted later if SAT is used in other places that might benefit from this improvement.
Omar Emara closed this pull request 2023-11-22 13:43:39 +01:00
All checks were successful
buildbot/vexp-code-patch-coordinator Build done.

Pull request closed

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
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#114191
No description provided.