Fix #114515: Cycles: Numerical precision issues in triangle light sampling #119224

Open
Lukas Stockner wants to merge 1 commits from LukasStockner/blender:triangle-sampling-precision into main

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

The refactor in 97d9bbbc97 changed the way q is computed in the spherical triangle sampling code. While the new approach is more efficient and saves a few operations, it introduces numerical precision issues for skinny/small (spherical) triangles.

Therefore, this change moves the computation of q back to the method from the paper, while keeping the more efficient solid angle computation.

Maybe there's a more elegant way to do this, @weizhen probably knows better. The main problem from what I can see are the cosine terms, since for small triangles cos_a/b/c will all be 0.9999..., which causes precision loss due to cancellation in many operations. To be honest, I'm surprised that this change is enough to make it work, I'd have expected all the other sin_from_cos etc. to also be problematic.

For example, here's a modified version of same glitch.blend from #114515:

Method main PR
Render main.png pr.png
Time 4m46s 4m55s
The refactor in 97d9bbbc97f8 changed the way `q` is computed in the spherical triangle sampling code. While the new approach is more efficient and saves a few operations, it introduces numerical precision issues for skinny/small (spherical) triangles. Therefore, this change moves the computation of `q` back to the method from the paper, while keeping the more efficient solid angle computation. Maybe there's a more elegant way to do this, @weizhen probably knows better. The main problem from what I can see are the cosine terms, since for small triangles `cos_a/b/c` will all be `0.9999...`, which causes precision loss due to cancellation in many operations. To be honest, I'm surprised that this change is enough to make it work, I'd have expected all the other `sin_from_cos` etc. to also be problematic. For example, here's a modified version of `same glitch.blend` from #114515: | Method | `main` | PR | |-|-|-| | Render | ![main.png](/attachments/1e3f814c-36b0-4546-b640-0d4a7e3238e8) | ![pr.png](/attachments/5ca1e2e1-0fd0-429f-83c1-8bfa0f24dbfe) | | Time | 4m46s | 4m55s |
127 KiB
157 KiB
Brecht Van Lommel was assigned by Lukas Stockner 2024-03-08 21:02:50 +01:00
Weizhen Huang was assigned by Lukas Stockner 2024-03-08 21:02:50 +01:00
Lukas Stockner added 1 commit 2024-03-08 21:03:01 +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
f5f248649b
Fix #114515: Cycles: Numerical precision issues in triangle light sampling
The refactor in 97d9bbbc97 changed the way q is computed in the spherical
triangle sampling code. While the new approach is more efficient and saves
a few operations, it introduces numerical precision issues for skinny/small
(spherical) triangles.

Therefore, this change moves the computation of q back to the method from
the paper, while keeping the more efficient solid angle computation.
Lukas Stockner added this to the Render & Cycles project 2024-03-08 21:03:06 +01:00
Brecht Van Lommel requested review from Brecht Van Lommel 2024-03-08 22:47:38 +01:00
Brecht Van Lommel requested review from Weizhen Huang 2024-03-08 22:47:38 +01:00
Brecht Van Lommel removed their assignment 2024-03-08 22:47:46 +01:00
Weizhen Huang was unassigned by Brecht Van Lommel 2024-03-08 22:47:46 +01:00
Weizhen Huang approved these changes 2024-03-08 23:28:50 +01:00
Weizhen Huang left a comment
Member

You should remove the computation of sin_b_sin_c_2 now that it's unused. Otherwise looks good.

Good that you figured out. The computation of sin_b_sin_c_2 and q had numerical issues. The other sin_from_coss are not called on small values so that seems fine.

You should remove the computation of `sin_b_sin_c_2` now that it's unused. Otherwise looks good. Good that you figured out. The computation of `sin_b_sin_c_2` and `q` had numerical issues. The other `sin_from_cos`s are not called on small values so that seems fine.

Can a test be added for this?

It could also go into 4.1.

@blender-bot build

Can a test be added for this? It could also go into 4.1. @blender-bot build
Some checks failed
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
Merge conflict checking is in progress. Try again in few moments.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u triangle-sampling-precision:LukasStockner-triangle-sampling-precision
git checkout LukasStockner-triangle-sampling-precision
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 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#119224
No description provided.