Fix #110255: Cover up CPU/GPU differences with small suns in light tree #110307
No reviewers
Labels
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#110307
Loading…
Reference in New Issue
No description provided.
Delete Branch "Alaska/blender:fix-small-sun-light-tree-sampling"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This pull request covers up a subtle difference between the CPU and GPU
when rendering with a light tree. Specifically a case where the user
has a sun light with a small angle.
The difference was caused by the dot() function being different between
CPU and GPU backends, with the GPU showing more meaningful
floating-point precision losses when working with small suns.
This pull request is for the Main branch of Blender, but should be back ported to the blender-v3.6-release branch if accepted.
For reference, here's an example of the issue:
In
light_tree_importance
there is a section of code that is run ifcos_theta >= cos_theta_u
. For distant lights this statement is always true. But on the GPU backend under specific circumstances, there were floating point precision losses which resulted in it not being true, resulting in the distant light not being sampled.This happens because when a sun light has a small angle (0 in this example), it has a high
cos_theta_u
(1 in this example).cos_theta_u = cos(sun_angle)
cos_theta
is calculated asdot(bcone.axis, -point_to_centroid)
, and in the case of distant lights,bcone.axis = -point_to_centroid
and both vectors are normalized, socos_theta
should be1
. But for some orientations of the sun lamp,cos_theta
was not equal to1
on the GPU. Insteadcos_theta
would be something like0.99999994
. This resulted in the if statement not being true, leading to the distant light having an importance of 0 and not being sampled.It should also be noted that I went with a "simple" fix to the issue, but it could have subtle effects on lights in other situations. Other fixes could also be implemented if you wish.
Some examples of alternative fixes I can think of are:
if (bcone.axis == -point_to_centroid)
then(cos_theta = 1)
otherwise usecos_theta = dot(bcone.axis, -point_to_centroid)
. From a quick look into the code, there's the potential for a floating point precision issue resulting inbcone.axis != -point_to_centroid
due to how they are calculated. But it should be fixed with #110374.if distance light
, then(cos_theta = 1)
Note: The floating point precision issues with the dot function aren't just a weird thing with the GPU. It's actually because the GPU and CPU run different code. Specifically the CPU takes advantage of SSE optimizations. If you swap the CPU over to using the same dot function as the GPU, then it will have the exact same issue.
Fix #110255: Cover up CPU/GPU differences in light tree.to Fix #110255: Cover up CPU/GPU differences with small suns in light tree5010b1d7d5
to8896301a7a
As pointed out earlier, the rendering error occurs on the GPU but not the CPU and this was due differences between the
dot()
function on the CPU and GPU. Specifically because the SSE optimisations used on the CPU produce a slightly different result due to floating point precision differences. If you remove the SSE code from thedot()
function, relying on the "simple math" that the GPU uses, then the CPU will have the exact same issues as the GPU.I tried to align the way the "simple math" version of
dot()
worked with the SSE operation. Specifically changing the order of operations and separating operations into different variables. And making those changes would fix the issue on the CPU with the SSE code removed, but wouldn't fix it on the GPU (I was testing the Metal backend), either due to some other issue or compiler optimisations. For reference, here are some examples of the different things I tried:As mentioned above, some tests did work to resolve the issue on the CPU with SSE code removed. But it didn't fix the issue on the GPU. Maybe there was a specific combination I missed?
Such value seems quite arbitrary, I would lean towards assigning 1 to
cos_theta
whenisequal(bcone.axis, -point_to_centroid)
and comment that dot product doesn't necessarily returns 1 in such cases due to precision issue.I guess part of the precision is already lost when normalizing the vector, which we can't fully recover in
dot()
.@ -187,3 +187,2 @@
* precision losses in the dot() function used to calculate cos_theta. */
float cos_min_outgoing_angle;
if ((cos_theta >= cos_theta_u) || (cos_theta_minus_theta_u >= cos_theta_o)) {
/* theta - theta_o - theta_u <= 0 */
Please keep this comment, thank you.
8896301a7a
to90e276682b
@Alaska / @weizhen , added this fix in 3.6 backporting list: #109399 :)
Feel free to remove the entry if commit includes breaking changes.