Cycles: Change sun lamp to have uniform intensity at high angles #108996

Merged
Weizhen Huang merged 6 commits from LukasStockner/blender:uniform-distant-light into main 2023-07-07 17:20:28 +02:00
Member

This fixes the issue described in #108957.

Instead of modeling distant lights like a disk light at infinity, it models them as cones. This way, the radiance is constant across the entire range of directions that it covers.

For smaller angles, the difference is very subtle, but for very large angles it becomes obvious (here's the file from #108957, the angle is 179°):

Old New
old_bigsun.png new_bigsun.png

One notable detail is the sampling method: Using sample_uniform_cone can increase noise, since the sampling method no longer preserves the stratification of the samples. This is visible in the "light tree multi distant" test scene.
Turns out we can do better, and after a bit of testing I found a way to adapt the concentric Shirley mapping to uniform cone sampling. I hope the comment explains the logic behind it reasonably well.

Here's the result, note that even the noise distribution is the same when using the new sampling:

Method Old New, basic sampling New, concentric sampling
Image old.png new_basic.png new_concentric.png
Render time (at higher spp) 9.03sec 8.79sec 8.96sec

I'm not sure if I got the light->normalized handling right, since I don't really know what the expectation from Hydra is here.

This fixes the issue described in https://projects.blender.org/blender/blender/issues/108957. Instead of modeling distant lights like a disk light at infinity, it models them as cones. This way, the radiance is constant across the entire range of directions that it covers. For smaller angles, the difference is very subtle, but for very large angles it becomes obvious (here's the file from #108957, the angle is 179°): | Old | New | | - | - | | ![old_bigsun.png](/attachments/4ef8e7a7-1a29-4bdf-a74c-3cfa103bf1e7) | ![new_bigsun.png](/attachments/d53c7749-2672-40b6-9048-ccf2fffceeb7) | One notable detail is the sampling method: Using `sample_uniform_cone` can increase noise, since the sampling method no longer preserves the stratification of the samples. This is visible in the "light tree multi distant" test scene. Turns out we can do better, and after a bit of testing I found a way to adapt the concentric Shirley mapping to uniform cone sampling. I hope the comment explains the logic behind it reasonably well. Here's the result, note that even the noise distribution is the same when using the new sampling: | Method | Old | New, basic sampling | New, concentric sampling | | - | - |- | - | | Image | ![old.png](/attachments/b3258a70-f015-4065-a774-193974cce439) | ![new_basic.png](/attachments/a9008576-0af6-4152-a687-c800fd958bbd) | ![new_concentric.png](/attachments/769b6c43-34bc-434e-a4fd-ce69addd1ba5) | | Render time (at higher spp)| 9.03sec | 8.79sec | 8.96sec | I'm not sure if I got the `light->normalized` handling right, since I don't really know what the expectation from Hydra is here.
Lukas Stockner added 1 commit 2023-06-15 02:54:45 +02:00
Lukas Stockner requested review from Brecht Van Lommel 2023-06-15 02:56:09 +02:00
Lukas Stockner added this to the Render & Cycles project 2023-06-15 02:56:12 +02:00
Brecht Van Lommel requested review from Weizhen Huang 2023-06-15 15:11:59 +02:00
Brecht Van Lommel approved these changes 2023-06-15 15:18:49 +02:00
Brecht Van Lommel left a comment
Owner

Thanks.

Thanks.
Member

I am unable to look into this patch properly this week because I am at a festival, but according to my experience cone sampling has severe numerical problems when the cone angle is small (is that the reason you are using if (angle > 1e-4f)?). I have a sample_uniform_cone_concentric() in #108506 that deals with small angles.

I am unable to look into this patch properly this week because I am at a festival, but according to my experience cone sampling has severe numerical problems when the cone angle is small (is that the reason you are using `if (angle > 1e-4f)`?). I have a sample_uniform_cone_concentric() in #108506 that deals with small angles.
Brecht Van Lommel added this to the 4.0 milestone 2023-06-15 15:43:42 +02:00
Author
Member

I am unable to look into this patch properly this week because I am at a festival, but according to my experience cone sampling has severe numerical problems when the cone angle is small (is that the reason you are using if (angle > 1e-4f)?). I have a sample_uniform_cone_concentric() in #108506 that deals with small angles.

Ah, yeah, good catch - looks like we both ended up deriving the same method, but your implementation has the terms simplified further, and using 1-cos(x) directly helps with numerical issues of course.

In my version, I indeed noticed problems when the angle becomes too small (makes sense, since there's not that much resolution around 1.0), that's why I put the limit there. Using the 1-cos(x) trick together with precise_angle should make that unnecessary, I'll give it a try.

> I am unable to look into this patch properly this week because I am at a festival, but according to my experience cone sampling has severe numerical problems when the cone angle is small (is that the reason you are using if (angle > 1e-4f)?). I have a sample_uniform_cone_concentric() in #108506 that deals with small angles. Ah, yeah, good catch - looks like we both ended up deriving the same method, but your implementation has the terms simplified further, and using `1-cos(x)` directly helps with numerical issues of course. In my version, I indeed noticed problems when the angle becomes too small (makes sense, since there's not that much resolution around 1.0), that's why I put the limit there. Using the `1-cos(x)` trick together with `precise_angle` should make that unnecessary, I'll give it a try.
Lukas Stockner added 1 commit 2023-06-16 02:02:32 +02:00
Author
Member

Okay, I've updated the PR. As far as I can tell, it behaves correctly for small angles (on the order of 0.01°) now.

For those angles, the previous dot(a, b) < cos(angle) actually becomes an issue, it stops working properly around 0.1° (due to the same cancellation issue - both values are almost 1).
This can be avoided with precise_angle, but for performance reasons I added a variant using fast_atan2f which is still more than sufficient here.

Performance numbers (quick test, not super reliable):

  • without PR: 9.03sec
  • before angle fix: 8.96sec
  • with angle fix and simplified math (thanks @weizhen): 8.46sec
  • with precise_angle: 9.25sec
  • with fast_atan2f: 8.74sec

Still faster than the original state, and now it's more robust for small angles and more consistent for large ones.

Okay, I've updated the PR. As far as I can tell, it behaves correctly for small angles (on the order of 0.01°) now. For those angles, the previous `dot(a, b) < cos(angle)` actually becomes an issue, it stops working properly around 0.1° (due to the same cancellation issue - both values are *almost* 1). This can be avoided with `precise_angle`, but for performance reasons I added a variant using `fast_atan2f` which is still more than sufficient here. Performance numbers (quick test, not super reliable): - without PR: 9.03sec - before angle fix: 8.96sec - with angle fix and simplified math (thanks @weizhen): 8.46sec - with `precise_angle`: 9.25sec - with `fast_atan2f`: 8.74sec Still faster than the original state, and now it's more robust for small angles *and* more consistent for large ones.
Weizhen Huang added 1 commit 2023-06-19 22:15:14 +02:00
Weizhen Huang added 1 commit 2023-06-19 22:25:09 +02:00
Member

I changed the eval_fac so that it gives the same intensity regardless of the angular diameter. I will change the description here #108505.

How does it look like without precise_angle()/vector_angle()? For me comparing with dot product seems to behave properly even at 1e-7f, so I wonder if this is platform-related, because of fast math or something.

I changed the `eval_fac` so that it gives the same intensity regardless of the angular diameter. I will change the description here #108505. How does it look like without `precise_angle()`/`vector_angle()`? For me comparing with dot product seems to behave properly even at `1e-7f`, so I wonder if this is platform-related, because of fast math or something.
Weizhen Huang added 1 commit 2023-06-20 16:36:55 +02:00
Weizhen Huang added 1 commit 2023-06-20 16:40:43 +02:00
Weizhen Huang approved these changes 2023-07-07 17:18:51 +02:00
Weizhen Huang merged commit 213204c229 into main 2023-07-07 17:20:28 +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 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#108996
No description provided.