Branched path unification #52725

Closed
opened 2017-09-13 15:32:48 +02:00 by Brecht Van Lommel · 19 comments

I'd like to unify path and branched path tracing, first to deduplicate code and improve performance on GPUs, and then to try to combine the best sampling strategies from both. The big difference between the two is that branched path tracing samples all lights and closures, instead of just 1.

The branched path code is not particularly efficient on either CUDA or OpenCL, and I think the best way to solve that is to use the same mechanism as we use for SSS in the path tracing megakernel, storing the state for each branch and restarting the path from that. This should also significantly simplify and deduplicate code.

The immediate problem is stack memory usage. Users can specify and arbitrarily high number of diffuse/glossy/... samples, and each sample would require extra state to be stored. We can address that in two ways:

  • Reduce size of the state that must be stored. I believe it can be reduced to about 200 bytes per branch, and possibly 150-100 bytes with more tricky optimizations.
  • With more branches there are quickly diminishing returns, if you have e.g. 16 branches that means you can cut the cost of the camera ray trace + shader evaluation to 1/16th, and at that point the cost of direct and indirect lighting are likely to be much bigger, and the branched path GPU code is already significantly slower. Extra AA samples to reduce aliasing, DoF and motion blur noise seems more useful at that point. So we could cap the number of branches, and if there are more closures sample only a subset of them.

Assuming we use 16 x 200 bytes = 3.2kb, that's the same memory usage as the current SSS stack, and not that big compared to the total 21k of the CUDA path tracing kernel. In fact I'm guessing the optimal branch factor for most scenes with GI is much lower than 16, but this needs to be tested with equal time renders of production scenes, which I plan to do in this task.

I'd like to unify path and branched path tracing, first to deduplicate code and improve performance on GPUs, and then to try to combine the best sampling strategies from both. The big difference between the two is that branched path tracing samples all lights and closures, instead of just 1. The branched path code is not particularly efficient on either CUDA or OpenCL, and I think the best way to solve that is to use the same mechanism as we use for SSS in the path tracing megakernel, storing the state for each branch and restarting the path from that. This should also significantly simplify and deduplicate code. The immediate problem is stack memory usage. Users can specify and arbitrarily high number of diffuse/glossy/... samples, and each sample would require extra state to be stored. We can address that in two ways: * Reduce size of the state that must be stored. I believe it can be reduced to about 200 bytes per branch, and possibly 150-100 bytes with more tricky optimizations. * With more branches there are quickly diminishing returns, if you have e.g. 16 branches that means you can cut the cost of the camera ray trace + shader evaluation to 1/16th, and at that point the cost of direct and indirect lighting are likely to be much bigger, and the branched path GPU code is already significantly slower. Extra AA samples to reduce aliasing, DoF and motion blur noise seems more useful at that point. So we could cap the number of branches, and if there are more closures sample only a subset of them. Assuming we use 16 x 200 bytes = 3.2kb, that's the same memory usage as the current SSS stack, and not that big compared to the total 21k of the CUDA path tracing kernel. In fact I'm guessing the optimal branch factor for most scenes with GI is much lower than 16, but this needs to be tested with equal time renders of production scenes, which I plan to do in this task.
Brecht Van Lommel self-assigned this 2017-09-13 15:32:48 +02:00
Author
Owner

Changed status to: 'Open'

Changed status to: 'Open'
Author
Owner

Added subscriber: @brecht

Added subscriber: @brecht

Added subscriber: @SteffenD

Added subscriber: @SteffenD

Added subscriber: @SterlingRoth

Added subscriber: @SterlingRoth

Added subscriber: @lsscpp

Added subscriber: @lsscpp
Author
Owner

Here's a few initial equal time renders from benchmark scenes, rendered on the CPU. The branched path settings have been tweaked to try to reduce noise, but there may exist better settings. The difficulty of tuning the settings is part of the reason we want to unify this though.

Path Branched Path Path + Defensive Sampling
bmw27 bmw27_path_200samples.png bmw27_branched_64samples.png bmw27_defensive_200samples.png
fishy_cat fishy_cat_path_572samples.png fishy_cat_branched_240samples.png fishy_cat_defensive_572samples.png
pabellon pabellon_path_110samples.png pabellon_branched_40samples.png pabellon_defensive_110samples.png

For bmw27, branched path has significantly less noise for the windows, but more noise for the headlights. Fishy cat seems to have some bug where we get different result, but ignoring that, it's difficult to determine a clear winner. The extra samples from path tracing help clean up the specular on the nose for example, but the grass DoF noise isn't reduced. For pabellon the clear winner seems to be path.

The noise on the windows in the bmw27 scene happens because the reflection closure has a very small weight and so very low probability of being sampled, but the area light it reflects is still quite bright due to low roughness. To mitigate this problem we can use defensive sampling (last column), giving the reflection closure a minimum weight. In branched path tracing both the reflection and refraction are always sampled so this problem does not happen (if samples are set to 1, then it's like assigning probability 0.5 to both closures for camera rays).

We can't do defensive sampling through all indirect bounces, since the closure weights compound and the sample weights start deviating too much from the actual contribution. Still there are cases where it makes sense to do for non-camera rays, like looking through a perfect mirror. So the test above is using a heuristic to stop defensive sampling at some point, but this needs further tweaking.

Note this will increase noise in some scenes, it is a matter of finding a balance. I expect this will be helpful also for the principled BSDF with diffuse + specular + coat layers.

Here's a few initial equal time renders from benchmark scenes, rendered on the CPU. The branched path settings have been tweaked to try to reduce noise, but there may exist better settings. The difficulty of tuning the settings is part of the reason we want to unify this though. | |Path|Branched Path|Path + Defensive Sampling| | -- | -- | -- | -- | |bmw27|![bmw27_path_200samples.png](https://archive.blender.org/developer/F796780/bmw27_path_200samples.png)|![bmw27_branched_64samples.png](https://archive.blender.org/developer/F796782/bmw27_branched_64samples.png)|![bmw27_defensive_200samples.png](https://archive.blender.org/developer/F796785/bmw27_defensive_200samples.png)| |fishy_cat|![fishy_cat_path_572samples.png](https://archive.blender.org/developer/F796790/fishy_cat_path_572samples.png)|![fishy_cat_branched_240samples.png](https://archive.blender.org/developer/F796792/fishy_cat_branched_240samples.png)|![fishy_cat_defensive_572samples.png](https://archive.blender.org/developer/F796794/fishy_cat_defensive_572samples.png)| |pabellon|![pabellon_path_110samples.png](https://archive.blender.org/developer/F796798/pabellon_path_110samples.png)|![pabellon_branched_40samples.png](https://archive.blender.org/developer/F796801/pabellon_branched_40samples.png)|![pabellon_defensive_110samples.png](https://archive.blender.org/developer/F796804/pabellon_defensive_110samples.png)| For bmw27, branched path has significantly less noise for the windows, but more noise for the headlights. Fishy cat seems to have some bug where we get different result, but ignoring that, it's difficult to determine a clear winner. The extra samples from path tracing help clean up the specular on the nose for example, but the grass DoF noise isn't reduced. For pabellon the clear winner seems to be path. The noise on the windows in the bmw27 scene happens because the reflection closure has a very small weight and so very low probability of being sampled, but the area light it reflects is still quite bright due to low roughness. To mitigate this problem we can use defensive sampling (last column), giving the reflection closure a minimum weight. In branched path tracing both the reflection and refraction are always sampled so this problem does not happen (if samples are set to 1, then it's like assigning probability 0.5 to both closures for camera rays). We can't do defensive sampling through all indirect bounces, since the closure weights compound and the sample weights start deviating too much from the actual contribution. Still there are cases where it makes sense to do for non-camera rays, like looking through a perfect mirror. So the test above is using a heuristic to stop defensive sampling at some point, but this needs further tweaking. Note this will increase noise in some scenes, it is a matter of finding a balance. I expect this will be helpful also for the principled BSDF with diffuse + specular + coat layers.

Added subscriber: @candreacchio

Added subscriber: @candreacchio

Added subscriber: @intrah

Added subscriber: @intrah

Added subscriber: @cardboard-2

Added subscriber: @cardboard-2

Added subscriber: @mib2berlin

Added subscriber: @mib2berlin

Added subscriber: @RainerTrummer

Added subscriber: @RainerTrummer

Added subscriber: @JasonClarke

Added subscriber: @JasonClarke
Member

Added subscriber: @Stefan_Werner

Added subscriber: @Stefan_Werner
Author
Owner

Here's a comparison using a shot from Agent, where branched path is the clear winner:

Path Branched Path
agent_dodges_path_192samples.png agent_dodges_branched_path_20samples.png

This scene has about 20 lights, and it seems to be branched path all light sampling that gives the main improvement. Since path tracing picks one light at random and every shading point is only significantly influenced by a subset of all lights, a lot of samples are wasted. So adding support for all light sampling to path tracing could help (and it's rather simple to implement). Or perhaps better a user specified N light samples. A light tree for importance sampling of many lights would also help (example ).

Branching for SSS is likely helpful as well as those areas are quite noisy. The problem there that we can't share direct lighting computations between BSDFs and BSSRDFs (much), so those pixels really need more samples and branching does that. Adaptive sampling could do this as well.

Here's a comparison using a shot from Agent, where branched path is the clear winner: |Path|Branched Path| | -- | -- | |![agent_dodges_path_192samples.png](https://archive.blender.org/developer/F817822/agent_dodges_path_192samples.png)|![agent_dodges_branched_path_20samples.png](https://archive.blender.org/developer/F817818/agent_dodges_branched_path_20samples.png)| This scene has about 20 lights, and it seems to be branched path all light sampling that gives the main improvement. Since path tracing picks one light at random and every shading point is only significantly influenced by a subset of all lights, a lot of samples are wasted. So adding support for all light sampling to path tracing could help (and it's rather simple to implement). Or perhaps better a user specified N light samples. A light tree for importance sampling of many lights would also help ([example ](https://sites.google.com/site/ckulla/home/many-lights)). Branching for SSS is likely helpful as well as those areas are quite noisy. The problem there that we can't share direct lighting computations between BSDFs and BSSRDFs (much), so those pixels really need more samples and branching does that. Adaptive sampling could do this as well.

Added subscriber: @frameshift

Added subscriber: @frameshift
Brecht Van Lommel removed their assignment 2020-01-18 14:24:54 +01:00

Added subscriber: @BeckersC

Added subscriber: @BeckersC
Member

Added subscriber: @Alaska

Added subscriber: @Alaska
Author
Owner

Changed status from 'Confirmed' to: 'Archived'

Changed status from 'Confirmed' to: 'Archived'
Author
Owner

Branched path was removed in 3.0.

Branched path was removed in 3.0.
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
14 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#52725
No description provided.