Cycles/EEVEE: change point light to double-sided sphere light #108506

Merged
Weizhen Huang merged 18 commits from weizhen/blender:point_light_to_sphere_light into main 2023-06-20 12:23:12 +02:00
Member

for energy preservation and better compatibility with other renderes. Ref: #108505

Point light now behaves the same as a spherical mesh light with the same overall energy (scaling from emission strength to power is (4\pi^2R^2)).

Cycles

Comparison

Mesh Light This patch Previous behavior
mesh_1024 sphere_1024 point_1024

The behavior stays the same when radius = 0.

This patch Previous behavior
sphere_64 point_64

No obvious performance change observed.

Sampling

When shading point lies outside the sphere, sample the spanned solid angle uniformly.
When shading point lies inside the sphere, sample spherical direction uniformly when inside volume or the surface is transmissive, otherwise sample cosine-weighted upper hemisphere.

Light Tree

When shading point lies outside the sphere, treat as a disk light spanning the same solid angle.
When shading point lies inside the sphere, it behaves like a background light, with estimated outgoing radiance

L_o=\int f_aL_i\cos\theta_i\mathrm{d}\omega_i=\int f_a\frac{E}{\pi r^2}\cos\theta_i\mathrm{d}\omega_i\approx f_a \frac{E}{r^2}

with f_a being the BSDF and E measure.energy in light_tree.cpp.
The importance calculation for LIGHT_POINT is

L_o=f_a E\cos\theta_i\frac{\cos\theta}{d^2}

Consider min_importance = 0 because maximal incidence angle is \pi, we could substitute d^2 with \frac{r^2}{2} so the averaged outgoing radiance is f_a \frac{E}{r^2}.
This only holds for non-transmissive surface, but should be fine to use in volume.

EEVEE

When shading point lies outside the sphere, the sphere light is equivalent to a disk light spanning the same solid angle. The sine of the new half-angle is the tangent of the previous half-angle.
When shading point lies inside the sphere, integrating over the cosine-weighted hemisphere gives 1.0.

Comparison with Cycles

The plane is diffuse, the blue sphere has specular component.

Before After
Cycles EEVEE Cycles EEVEE

TODO

  • Point light should be renamed as sphere light at various places.
  • Overlay and gizmo should adapt to the new size, but they share the same code with spot light, so maybe wait until changes for spot light.
for energy preservation and better compatibility with other renderes. Ref: #108505 Point light now behaves the same as a spherical mesh light with the same overall energy (scaling from emission strength to power is \(4\pi^2R^2\)). # Cycles ## Comparison | Mesh Light | This patch | Previous behavior | | -------- | -------- | -------- | | ![mesh_1024](attachments/2900954c-57f8-49c2-b6f3-8fb559b820ac) | ![sphere_1024](attachments/148241ca-9350-48b6-be04-3933e015424c) | ![point_1024](attachments/d9b19d54-2b00-4986-ba8c-c4b28f687f09) | The behavior stays the same when `radius = 0`. | This patch | Previous behavior | | -------- | -------- | | ![sphere_64](attachments/aa05d59a-146a-4f69-b257-5d09a7f41d4e) | ![point_64](attachments/69a743be-bc15-454b-92d8-af02f4e8ab07) | No obvious performance change observed. ## Sampling When shading point lies outside the sphere, sample the spanned solid angle uniformly. When shading point lies inside the sphere, sample spherical direction uniformly when inside volume or the surface is transmissive, otherwise sample cosine-weighted upper hemisphere. ## Light Tree When shading point lies outside the sphere, treat as a disk light spanning the same solid angle. When shading point lies inside the sphere, it behaves like a background light, with estimated outgoing radiance \[L_o=\int f_aL_i\cos\theta_i\mathrm{d}\omega_i=\int f_a\frac{E}{\pi r^2}\cos\theta_i\mathrm{d}\omega_i\approx f_a \frac{E}{r^2}\], with \(f_a\) being the BSDF and \(E\) `measure.energy` in `light_tree.cpp`. The importance calculation for `LIGHT_POINT` is \[L_o=f_a E\cos\theta_i\frac{\cos\theta}{d^2}\]. Consider `min_importance = 0` because maximal incidence angle is \(\pi\), we could substitute \(d^2\) with \(\frac{r^2}{2}\) so the averaged outgoing radiance is \(f_a \frac{E}{r^2}\). This only holds for non-transmissive surface, but should be fine to use in volume. # EEVEE When shading point lies outside the sphere, the sphere light is equivalent to a disk light spanning the same solid angle. The sine of the new half-angle is the tangent of the previous half-angle. When shading point lies inside the sphere, integrating over the cosine-weighted hemisphere gives 1.0. ## Comparison with Cycles The plane is diffuse, the blue sphere has specular component. | Before | |After || |---|--|--|--| |Cycles|EEVEE|Cycles|EEVEE| |![](attachments/5824c494-0645-461a-b193-d74e02f353b8)|![](attachments/d2e85b53-3c2a-4a9f-a3b2-6e11c6083ce0)|![](attachments/a8dcdd8b-c13c-4fdc-808c-2563624549be)|![](attachments/8c3618ef-1ab4-4210-9535-c85e873f1e45)| # TODO - [ ] Point light should be renamed as sphere light at various places. - [ ] Overlay and gizmo should adapt to the new size, but they share the same code with spot light, so maybe wait until changes for spot light.
Weizhen Huang added the
Module
Render & Cycles
label 2023-06-01 11:32:59 +02:00
Weizhen Huang added 7 commits 2023-06-01 11:33:11 +02:00
Weizhen Huang force-pushed point_light_to_sphere_light from 0153e574cd to abcacaa58e 2023-06-01 14:02:52 +02:00 Compare
Weizhen Huang added 1 commit 2023-06-02 16:32:51 +02:00
Weizhen Huang added 1 commit 2023-06-08 14:49:48 +02:00
Weizhen Huang force-pushed point_light_to_sphere_light from 00b3bd8f23 to 19bf32dcc6 2023-06-08 15:24:00 +02:00 Compare
Weizhen Huang added 1 commit 2023-06-09 20:08:25 +02:00
Weizhen Huang added 2 commits 2023-06-19 12:52:38 +02:00
Weizhen Huang changed title from WIP: Cycles: change point light to sphere light to Cycles/EEVEE: change point light to sphere light 2023-06-19 13:39:04 +02:00
Weizhen Huang added the
Interest
EEVEE & Viewport
label 2023-06-19 13:41:11 +02:00
Weizhen Huang added 1 commit 2023-06-19 14:40:07 +02:00
Weizhen Huang changed title from Cycles/EEVEE: change point light to sphere light to Cycles/EEVEE: change point light to double-sided sphere light 2023-06-19 15:45:00 +02:00
Weizhen Huang added 1 commit 2023-06-19 16:01:47 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
8e0055a919
Substitute with enlarged disk light for light tree
Weizhen Huang requested review from Brecht Van Lommel 2023-06-19 16:05:27 +02:00
Weizhen Huang requested review from Sergey Sharybin 2023-06-19 16:05:36 +02:00
Weizhen Huang requested review from Clément Foucault 2023-06-19 16:05:44 +02:00
Sergey Sharybin reviewed 2023-06-19 16:12:24 +02:00
@ -23,2 +18,2 @@
if (radius > 0.0f) {
ls->P += disk_light_sample(lightN, rand) * radius;
float3 lightN = P - klight->co;
const float d_sqr = len_squared(lightN);

The Blender convention is to use _sq suffix.

The Blender convention is to use `_sq` suffix.
weizhen marked this conversation as resolved

@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/PR108506) when ready.
Brecht Van Lommel approved these changes 2023-06-19 18:35:44 +02:00
Brecht Van Lommel left a comment
Owner

I wish I could point out a mistake because this way it seems like I didn't really review it, but I couldn't spot one. Benchmark scenes look ok too.

I wish I could point out a mistake because this way it seems like I didn't really review it, but I couldn't spot one. Benchmark scenes look ok too.
Clément Foucault approved these changes 2023-06-19 20:23:08 +02:00
Clément Foucault reviewed 2023-06-19 20:26:07 +02:00
@ -159,2 +176,2 @@
points[0] = Px * -ld._area_size_x + Py * -ld._area_size_y;
points[1] = Px * ld._area_size_x + Py * -ld._area_size_y;
if (ld.type == LIGHT_POINT) {
/* Sphere light spans a larger angle than a disk light with the same radius (sin -> tan). */

This sin -> tan is a bit cryptic. It could help if it was a full sentence.

This `sin -> tan` is a bit cryptic. It could help if it was a full sentence.
weizhen marked this conversation as resolved
Weizhen Huang added 1 commit 2023-06-19 23:04:36 +02:00
Weizhen Huang merged commit a4d792a3ad into main 2023-06-20 12:23:12 +02:00
Weizhen Huang deleted branch point_light_to_sphere_light 2023-06-20 12:23:14 +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
5 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#108506
No description provided.