Fix #119692: Account for mesh lights with a light tree root index of 0 #119770

Merged
Brecht Van Lommel merged 2 commits from Alaska/blender:fix-119692-tree-flatten into main 2024-03-25 14:47:30 +01:00
Member

When using light linking with the light tree, the root index of a
mesh light subtree can be 0. The current code assumed this wasn't
possible, and as such it caused rendering issues, specifically the
incorrect computation of the PDF of certain mesh lights during
forward path tracing.

So we adjust the code to allow mesh light subtree root node
indexs of 0.

This was worked on by @Alaska, @Sergey, and @weizhen

When using light linking with the light tree, the root index of a mesh light subtree can be 0. The current code assumed this wasn't possible, and as such it caused rendering issues, specifically the incorrect computation of the PDF of certain mesh lights during forward path tracing. So we adjust the code to allow mesh light subtree root node indexs of 0. This was worked on by @Alaska, @Sergey, and @weizhen
Alaska added the
Module
Render & Cycles
label 2024-03-22 06:03:21 +01:00
Alaska changed title from WIP: Fix #119692: Ensure light tree node 0 can't be a leaf node. to Draft: Fix #119692: Ensure light tree node 0 can't be a leaf node. 2024-03-22 07:22:33 +01:00

I've spent some time looking into the results of the flattening code, but i could not see anything obviously wrong. So then I've started looking into the light_tree_sample and light_tree_pdf, while keeping in mind your findings.

I think what actually is happening is the light_tree_pdf which uses root_index != 0 as some sort of indication that leaf node is a mesh light, and need to fetch its subtree. When light linking is not used root_index = 0 indicates the scene tree, and anything else indicates some other subtree. With light linking enabled it is possible to have a subtree's root_index which is not 0.

So I think the fix as as easy as making it root_index = -1 to indicate that subtree is not needed to be traversed. Attached a fix for it.

I've spent some time looking into the results of the flattening code, but i could not see anything obviously wrong. So then I've started looking into the `light_tree_sample` and `light_tree_pdf`, while keeping in mind your findings. I think what actually is happening is the `light_tree_pdf` which uses `root_index != 0` as some sort of indication that leaf node is a mesh light, and need to fetch its subtree. When light linking is not used `root_index = 0` indicates the scene tree, and anything else indicates some other subtree. With light linking enabled it is possible to have a subtree's `root_index` which is not 0. So I think the fix as as easy as making it `root_index = -1` to indicate that subtree is not needed to be traversed. Attached a fix for it.
Alaska force-pushed fix-119692-tree-flatten from a2b3eb9995 to 1cd5c1e758 2024-03-22 15:48:21 +01:00 Compare
Alaska changed title from Draft: Fix #119692: Ensure light tree node 0 can't be a leaf node. to Fix #119692: Account for mesh lights with a light tree root index of 0 2024-03-22 15:48:32 +01:00
Alaska requested review from Sergey Sharybin 2024-03-22 15:48:46 +01:00
Alaska requested review from Weizhen Huang 2024-03-22 15:48:54 +01:00
Alaska requested review from Brecht Van Lommel 2024-03-22 15:49:00 +01:00
Author
Member

I'm currently targeting the main branch of Blender for this pull request. Feel free to rebase against blender-v4.1-release.

I'm currently targeting the main branch of Blender for this pull request. Feel free to rebase against blender-v4.1-release.
Member

@Sergey I am not sure if you misunderstood something or it was just typo, but without light linking 0 is the index of root node of the main tree, and the mesh lights have subtrees with non-zero root_index. Not sure about the logic with light linking.

@Sergey I am not sure if you misunderstood something or it was just typo, but without light linking `0` is the index of root node of the main tree, and the mesh lights have subtrees with non-zero `root_index`. Not sure about the logic with light linking.
Author
Member

The code change proposed by Sergey (and is now in the current iteration of this pull request) is fine by me. I made the same fix (but with a different method) earlier with 1caa6716d9 (In my local repo only). Although the explaintion Sergey provided seems to be a bit backwards in some areas based on my understanding of the code.

I still find it odd that node_index 0 can't be a leaf node with light linking disabled, but it's possible with light linking enabled. And that's what a2b3eb9995 (From the earlier iteration of this pull request) attempted to fix. But it's up to the Cycles developers at this point to decide which approach they want to take.

The code change proposed by Sergey (and is now in the current iteration of this pull request) is fine by me. I made the same fix (but with a different method) earlier with https://projects.blender.org/Alaska/blender/commit/1caa6716d9f37d53d34715b25bed9f843c556ff1 (In my local repo only). Although the explaintion Sergey provided seems to be a bit backwards in some areas based on my understanding of the code. I still find it odd that node_index 0 can't be a leaf node with light linking disabled, but it's possible with light linking enabled. And that's what https://projects.blender.org/blender/blender/commit/a2b3eb99955b91589597ee00554ab2c8c7c300b3 (From the earlier iteration of this pull request) attempted to fix. But it's up to the Cycles developers at this point to decide which approach they want to take.
Member

@Alaska without light linking, the right child of the root node is always reserved for distant/backgrounds lights, even if they are not present in the scene, so 0 can't be the leaf.
I do not remember the exact reason I did that, maybe it was just simpler for the implementation.

@Alaska without light linking, the right child of the root node is always reserved for distant/backgrounds lights, even if they are not present in the scene, so `0` can't be the leaf. I do not remember the exact reason I did that, maybe it was just simpler for the implementation.

With the light linking we had to get rid of some assumptions about the tree topology, and store things in a more flexible manner, and some parts of the trees are filled in first. So while the statement about right child reserved for a distant for scene tree is still expected to be valid, you can not come to a conclusion about what node with index 0 is. It might or night not be root.

Although the explaintion Sergey provided seems to be a bit backwards in some areas based on my understanding of the code.

Yeah, I think i've mixed the = 0 and != 0 in the explanation. Corrected it now.

With the light linking we had to get rid of some assumptions about the tree topology, and store things in a more flexible manner, and some parts of the trees are filled in first. So while the statement about right child reserved for a distant for scene tree is still expected to be valid, you can not come to a conclusion about what node with index 0 is. It might or night not be root. > Although the explaintion Sergey provided seems to be a bit backwards in some areas based on my understanding of the code. Yeah, I think i've mixed the `= 0` and `!= 0` in the explanation. Corrected it now.
Sergey Sharybin approved these changes 2024-03-22 16:33:23 +01:00
Sergey Sharybin left a comment
Owner

Attaching file from the report which would be handy to add to our regression suit.

Attaching file from the report which would be handy to add to our regression suit.
Member

If we can not make the assumption anymore that the root index of the main tree is 0, and root_index is only used for traversing subtree here, I would rename it to subtree_index, or subtree_root. This way it's much less confusing, because assigning root_index = -1 has no concrete meaning to me, while subtree_index = -1 seems clear to indicate a subtree does not exist.

If we can not make the assumption anymore that the root index of the main tree is 0, and `root_index` is only used for traversing subtree here, I would rename it to `subtree_index`, or `subtree_root`. This way it's much less confusing, because assigning `root_index = -1` has no concrete meaning to me, while `subtree_index = -1` seems clear to indicate a subtree does not exist.
Alaska added 1 commit 2024-03-23 01:04:06 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
310e67a4de
Improve naming of the root_index as suggested by Weizhen
Brecht Van Lommel approved these changes 2024-03-25 10:37:58 +01:00

@blender-bot build

@blender-bot build
Brecht Van Lommel merged commit 43cef92f66 into main 2024-03-25 14:47:30 +01:00
Brecht Van Lommel deleted branch fix-119692-tree-flatten 2024-03-25 14:47:32 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser Project (Legacy)
Interest
Asset System
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
4 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#119770
No description provided.