Environment Importance Sampling gives too much noise #69745
Labels
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
12 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#69745
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When using importance sampling for environment maps in Cycles, the default/recommended resolution gives too noisy results when texture interpolation other than "closest" is selected.
Blender version: 2.80
To reproduce:
Actual result:
Second render has much more noise.
Expected result:
Little to no difference in noise.
Additional testing:
Result: Reduced noise again.
envmap.blend
(HDRI image by Greg Zaal, HDRI Haven, CC0 license)
Added subscriber: @Stefan_Werner
#73832 was marked as duplicate of this issue
Working theory:
When building the initial distribution, Cycles always sample the center of a pixel, effectively a closest or box filter. When using the distribution later during the render with a different filter, we get a mismatch between the function and its PDF. When sampled with linear texture filtering, single bright pixels become spikes that bleed into the neighboring pixels, where the distribution we sample from is piecewise linear over the pixel with no bleeding.
Note also how the noise is also reduced when using cubic interpolation.
Added subscriber: @LukasStockner
In the past, I've considered tweaking the sampling algorithm to sample from a piecewise linear function instead of piecewise constant, but that would only help if the CDF map exactly aligns with the background image.
In practice, it might be simpler to just replace each pixel in the CDF by the maximum of it's 3x3 neighborhood. This will make the sampling a bit less accurate but should help with the fireflies due to undersampling and interpolation.
Added subscriber: @brecht
I think the sampling is already piecewise linear? But it's only along one axis at a time which may be the problem.
We compute a CDF per row, and then a CDF of all those rows. That means if you have a dark pixel with a bright pixel just below, within that row it will not get more importance. The row as a whole will get more samples, but not that specific pixel.
To help with that problem, we could use the average of the pixel and the adjacent pixel above/below when building the CDF per row. Which isn't really that different than what you guys are proposing, and maybe max or some other filter works better. Just a different way of approaching it conceptually.
The current code samples the CDF as a piecewise linear function, but the underlying PDF is piecewise constant since it's the derivative of the CDF.
I think the problem here is that interpolation essentially allows bright pixels to "leak" into parts if their neighbors, but the neighbors don't receive a high PDF.
Therefore the suggestion of the 3x3 filter before computing the marginal and conditional CDFs - if we only average between neighboring rows, we will still have this problem in the y axis.
A slightly more conservative approach might be to use a weighted 3x3 grid where the center pixel has higher weight - that way, massively brighter pixels will still increase the PDF of their neighbors to avoid strong fireflies, but the overall impact on quality might be reduced.
I just played with 2x2 supersampling when generating the distribution, thus avoiding sampling texels exactly in the middle. This allows for texture filtering to contribute more, as opposed to sampling texels in their exact center which makes the linear filter behave exactlylike the closest filter.
The result is a significant reduction in noise with linear interpolation, although still noisier as with closest interpolation.
PBRT filters the environment map when creating the distribution:
http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Sampling_Light_Sources.html#sec:mc-infinite-area-lights
Added subscriber: @YAFU
A comment perhaps related to this.
When Portals was introduced in Blender, many users clearly obtained very good results in tests regarding less noise using Portals. This is because Multiple Importance Sampling was disabled by default in Blender when creating a new scene (2.76b for example).
But then with new versions of Blender users in forums began to question the good result of Portals compared to not using Portals, and I am pretty sure that it started to happen when in Blender Multiple Importance Sampling it started to be enabled by default in scenes. In my tests with new versions of Blender, I only get clear better results using Portals when Multiple Importance Sampling is disabled (Sampling = None). If multiple importance sampling is used, the higher the Map Resolution value is, the smaller the difference in the Portals vs. No Portals comparison with respect to the amount of noise.
I'm fine with a some empirically determined prefiltering.
To me it seems possible to figure out the code to do piecewise linear sampling in a way that exactly matches the linear interpolation (at least in 1D and close enough in 2D). But we don't need to wait for that if we can do something simple already.
This comment was removed by @Stefan_Werner
I played a bit with simple filters for the distribution. Both 3x3 box and 3x3 Gaussian filters improve the case with linear texture filtering, but make things worse for closest texture filtering.
You can auto detect closest filtering along with the resolution, and leave out the filtering then.
2x2 supersampling inside kernel_background_evaluate() reduces noise more than filtering when generating the distribution and leaves the quality intact with other texture filters. It should also improve the situation for procedural high-frequency environment maps. My vote would be for supersampling.
I attached my test patches so others can test for themselves. They are not optimized, there are faster filter implementations that use less memory.
Best quality still comes with the closest texture interpolation, I assume because the distribution is a perfect match for the function. Linear texture interpolation is better with supersampling, although still not as good as when I increase the size of the distribution to 4x env map resolution.
filter_distribution.diff
supersampling.diff
Added subscribers: @irfancelik, @mont29, @WilliamReynish
Added subscriber: @filibis
Added subscriber: @SteffenD
Added subscriber: @ReinhardK
Added subscriber: @lsscpp
Hopefully here is the right place for this.
I noticed that Smart interpolation is not the same on GPU or CPU. On a simple scene derived from envmap.blend (at the top of this page, I just put Suzanne into a cube with a simple window to let the light in) CPU "Smart" interpolation looks just like "Cubic" while the GPU tiles look like "Linear" without noise. I hope jpeg codec doesn't kills too much the detail (edit: uploaded pngs ;), anyway, blue arrows point to the boundaries of CPU/GPU tiles, and also the magenta one with the difference that it's a harsh horizontal line (CPU/GPU boundary) in the middle of the shadow.
Notice that none of the other interpolations give this differences/artifacts.
Here a screenshot that shows which tiles where evaluated by CPU
And here's the edited blend
envmap.blend
Added subscriber: @xdanic
Added subscriber: @Alaska
Added subscriber: @Josephbburg
Perhaps this is why? It says it's OSL only, and of course OSL isn't fully supported on the GPU.
Maybe that is something related, nice spot. But I would expect the opposite result, since smart interpolation looks better on GPU, and on CPU seems to work as cubic.
Now I wonder, if CPU is smart and GPU falls back to linear, why there are no fireflies? Can't we have CPU falling back to the same "linear mode” that gives no sampling issue?
I have no pc at hand for a week, but the easy test would be: exclude CPU from rendering, and make two gpu-only renders, one linear and one smart. I'd expect two identical renders except for fireflies