Shadow linking: Initial work towards MIS support #107439

Merged
Sergey Sharybin merged 17 commits from Sergey/blender:cycles-light-linking-mis into cycles-light-linking 2023-05-05 21:44:14 +02:00

The goal of this change is to make it so the emitters are not forced
to have MIS disabled when shadow linking in used. On the user level
it means that lights sources sources which are behind excluded shadow
blocker will be visible in sharp glossy reflection.

In order to support this an extra shadow ray is traced in the direction
of the main path, to gather contribution of emitters behind shadow
blockers. This is done in the two new kernels.

First kernel performs light intersection to see if the extra shadow
ray is needed. It is not needed if, for example, there are no light
sources in the direction of the main path.

The second kernel shades the light source and generates the actual
shadow path.

Such separation allows to keep kernels small (so that no intersection
and shading happens in the same kernel). It also helps having good
occupancy on the GPU: the main path will not wait for the shadow
kernels to complete before continuing (the main path is needed by the
extra shadow path generation, to have access to direction and shading
reading state).

Current implementation is limited to lights only: there is no support
of mesh lights yet.

The MIS weight of the new shadow ray needs to be double-checked. It was
verified to give same result as the main path when the same light is
hit.

To avoid contribution from the same light source counted by the shadow
ray and the main path the light source which was chosen to trace the
shadow ray to is excluded from intersection via transparent bounces.
This seems unideal and feels that it could be done via some MIS wights
as well. Doing so is an exercise for later.

The kernel naming could be improved. Suggestions are welcome.
There are also quiet some TODOs in the code. Not sure how much of those
must be resolved prior to merge to the cycles-light-linking branch.
Would be cool to have extra eyes on some of the MIS aspects, which is
easier in the shared branch.

Tested on the CPU and Metal on M2 GPU.

Ref #104972

Example:
shadow_linking_glossy.png

The goal of this change is to make it so the emitters are not forced to have MIS disabled when shadow linking in used. On the user level it means that lights sources sources which are behind excluded shadow blocker will be visible in sharp glossy reflection. In order to support this an extra shadow ray is traced in the direction of the main path, to gather contribution of emitters behind shadow blockers. This is done in the two new kernels. First kernel performs light intersection to see if the extra shadow ray is needed. It is not needed if, for example, there are no light sources in the direction of the main path. The second kernel shades the light source and generates the actual shadow path. Such separation allows to keep kernels small (so that no intersection and shading happens in the same kernel). It also helps having good occupancy on the GPU: the main path will not wait for the shadow kernels to complete before continuing (the main path is needed by the extra shadow path generation, to have access to direction and shading reading state). Current implementation is limited to lights only: there is no support of mesh lights yet. The MIS weight of the new shadow ray needs to be double-checked. It was verified to give same result as the main path when the same light is hit. To avoid contribution from the same light source counted by the shadow ray and the main path the light source which was chosen to trace the shadow ray to is excluded from intersection via transparent bounces. This seems unideal and feels that it could be done via some MIS wights as well. Doing so is an exercise for later. The kernel naming could be improved. Suggestions are welcome. There are also quiet some TODOs in the code. Not sure how much of those must be resolved prior to merge to the cycles-light-linking branch. Would be cool to have extra eyes on some of the MIS aspects, which is easier in the shared branch. Tested on the CPU and Metal on M2 GPU. Ref #104972 Example: ![shadow_linking_glossy.png](/attachments/3bd75b55-e0f2-49b4-954a-f65b78ce7028)
Sergey Sharybin added the
Module
Render & Cycles
label 2023-04-28 15:38:01 +02:00
Sergey Sharybin added 1 commit 2023-04-28 15:38:06 +02:00
88abd725cc Shadow linking: Initial work towards MIS support
The goal of this change is to make it so the emitters are not forced
to have MIS disabled when shadow linking in used. On the user level
it means that lights sources sources which are behind excluded shadow
blocker will be visible in sharp glossy reflection.

In order to support this an extra shadow ray is traced in the direction
of the main path, to gather contribution of emitters behind shadow
blockers. This is done in the two new kernels.

First kernel performs light intersection to see if the extra shadow
ray is needed. It is not needed if, for example, there are no light
sources in the direction of the main path.

The second kernel shades the light source and generates the actual
shadow path.

Such separation allows to keep kernels small (so that no intersection
and shading happens in the same kernel). It also helps having good
occupancy on the GPU: the main path will not wait for the shadow
kernels to complete before continuing (the main path is needed by the
extra shadow path generation, to have access to direction and shading
reading state).

Current implementation is limited to lights only: there is no support
of mesh lights yet.

The MIS weight of the new shadow ray needs to be double-checked. It was
verified to give same result as the main path when the same light is
hit.

To avoid contribution from the same light source counted by the shadow
ray and the main path the light source which was chosen to trace the
shadow ray to is excluded from intersection via transparent bounces.
This seems unideal and feels that it could be done via some MIS wights
as well. Doing so is an exercise for later.

The kernel naming could be improved. Suggestions are welcome.
There are also quiet some TODOs in the code. Not sure how much of those
must be resolved prior to merge to the cycles-light-linking branch.
Would be cool to have extra eyes on some of the MIS aspects, which is
easier in the shared branch.

Tested on the CPU and Metal on M2 GPU.
Sergey Sharybin requested review from Brecht Van Lommel 2023-04-28 15:38:18 +02:00
Sergey Sharybin requested review from Weizhen Huang 2023-04-28 15:38:23 +02:00
Sergey Sharybin added this to the Render & Cycles project 2023-04-28 15:38:27 +02:00
Brecht Van Lommel requested changes 2023-05-03 19:04:49 +02:00
@ -29,3 +30,4 @@
REGISTER_KERNEL(integrator_shade_shadow),
REGISTER_KERNEL(integrator_shade_surface),
REGISTER_KERNEL(integrator_shade_volume),
REGISTER_KERNEL(integrator_shade_blocked_light),

Not sure what a good name is. Best I could think of so far is to rename blocked_light -> light_dedicated.

Not sure what a good name is. Best I could think of so far is to rename `blocked_light` -> `light_dedicated`.
@ -0,0 +69,4 @@
/* Store light towards which the shadow ray is cast.
* This light will be excluded from the main path MIS it is hit, avoiding counting contribution
* twice. */

I don't think excluding one specific light works. Other shadow linked lights also should not contribute, since they would not have proper blocker visibility.

We should exclude all lights (with shadow linking or just all) from contributing through the indirect light ray.

I don't think excluding one specific light works. Other shadow linked lights also should not contribute, since they would not have proper blocker visibility. We should exclude all lights (with shadow linking or just all) from contributing through the indirect light ray.
@ -0,0 +62,4 @@
return;
}
const uint32_t path_flag = INTEGRATOR_STATE(state, path, flag);

This is missing a test of the SHADER_EXCLUDE flags as found in shade_light.h.

This is missing a test of the `SHADER_EXCLUDE` flags as found in `shade_light.h`.
@ -0,0 +68,4 @@
float mis_weight = 1.0f;
if (!(path_flag & PATH_RAY_MIS_SKIP)) {
const float mis_ray_pdf = INTEGRATOR_STATE(state, path, mis_ray_pdf);
mis_weight = light_sample_mis_weight_nee(kg, ls.pdf, mis_ray_pdf);

This should be light_sample_mis_weight_forward_lamp.

The ray direction was chosen by BSDF sampling (forward), not light sampling (next event estimation).

This should be `light_sample_mis_weight_forward_lamp`. The ray direction was chosen by BSDF sampling (forward), not light sampling (next event estimation).
Sergey Sharybin added 4 commits 2023-05-04 10:06:56 +02:00
cd4b5f1f61 Take shader ray visibility into account
Refactored code a bit so that there is less duplication.

The downside is that the camera ray visibility for light shader
is now checked twice (in the intersect_closest and shade_light),
but it is unlikely to cause measurable performance impact.
Sergey Sharybin added 2 commits 2023-05-04 17:43:02 +02:00
Sergey Sharybin added 1 commit 2023-05-04 18:01:09 +02:00
bdf4f318b6 Fix mistake in the lights intersection
The previous change to the way how lights are ignored made it so
lights are ignored by the dedicated shadow ray as well.
Sergey Sharybin added 1 commit 2023-05-05 12:45:49 +02:00
Sergey Sharybin added 1 commit 2023-05-05 16:17:12 +02:00
Sergey Sharybin added 1 commit 2023-05-05 17:14:02 +02:00
Sergey Sharybin added 1 commit 2023-05-05 17:16:42 +02:00
Sergey Sharybin added 1 commit 2023-05-05 17:30:37 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
1fcd34b2a8
Properly support volumes
Trace a dedicated light shadow ray for scatter events.

Makes it so a volume scene with a distant shadow-linked (excluded)
object renders the same as the scene without shadow linking at all.
Author
Owner

@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/PR107439) when ready.
Sergey Sharybin added 1 commit 2023-05-05 17:39:27 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
2e632df524
Fix old variable names used in OptiX
Author
Owner

@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/PR107439) when ready.
Sergey Sharybin added 1 commit 2023-05-05 17:59:08 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
9794cc5862
Fix compilation of GPU kernels
Author
Owner

@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/PR107439) when ready.
Sergey Sharybin added 1 commit 2023-05-05 18:20:05 +02:00
Author
Owner

@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/PR107439) when ready.
Brecht Van Lommel approved these changes 2023-05-05 20:39:33 +02:00
Brecht Van Lommel left a comment
Owner

I didn't spot issues besides what is already marked as TODO.

I didn't spot issues besides what is already marked as TODO.
@ -247,2 +328,2 @@
IntegratorShadowState shadow_state = integrator_shadow_path_init(
kg, state, DEVICE_KERNEL_INTEGRATOR_INTERSECT_SHADOW, false);
if (ray.self.object != OBJECT_NONE) {
// TODO: Why is it needed here? The light_sample_to_surface_shadow_ray offsets the ray.

It's a different type of offset. This one for float precision issues, the other one is for differences between smooth normals and actual geometry.

It's a different type of offset. This one for float precision issues, the other one is for differences between smooth normals and actual geometry.
Author
Owner

Ah, duuh. Now when you explained it, seems obvious. Thanks for explanation! :)

Ah, duuh. Now when you explained it, seems obvious. Thanks for explanation! :)
Sergey Sharybin added 1 commit 2023-05-05 21:41:26 +02:00
Sergey Sharybin merged commit 356e26a4e6 into cycles-light-linking 2023-05-05 21:44:14 +02:00
Sergey Sharybin deleted branch cycles-light-linking-mis 2023-05-05 21:44:15 +02:00
Brecht Van Lommel removed this from the Render & Cycles project 2023-05-24 19:05:21 +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#107439
No description provided.