Commit Graph

41 Commits

Author SHA1 Message Date
Brecht Van Lommel
a428815716 Fix: Cycles light tree poor when light normalize is off
This option was not exposed in the Blender UI, so no user visible effect.
Take into account light area when building light tree.

Ref #136958
2025-05-22 16:32:44 +02:00
Brecht Van Lommel
e813e46327 Cycles: Refactor lights to be objects
This is an intermediate steps towards making lights actual geometry.
Light is now a subclass of Geometry, which simplifies some code.

The geometry is not added to the BVH yet, which would be the next
step and improve light intersection performance with many lights.

This makes object attributes work on lights.

Co-authored-by: Lukas Stockner <lukas@lukasstockner.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/134846
2025-02-24 23:44:14 +01:00
Brecht Van Lommel
21a90f26b6 Cleanup: Fix C++20 deprecation warnings in Cycles
Pull Request: https://projects.blender.org/blender/blender/pulls/134338
2025-02-11 16:42:03 +01:00
Brecht Van Lommel
57ff24cb99 Refactor: Cycles: Add const keyword to more function parameters
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:24 +01:00
Brecht Van Lommel
dd51c8660b Refactor: Cycles: Add const keyword where possible, using clang-tidy
Check was misc-const-correctness, combined with readability-isolate-declaration
as suggested by the docs.

Temporarily clang-format "QualifierAlignment: Left" was used to get consistency
with the prevailing order of keywords.

Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:20 +01:00
Brecht Van Lommel
5c46063607 Refactor: Cycles: Make kernel headers work by themselves
Shuffle around some code and add more includes so that individual
header files compile without errors.

Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:22:50 +01:00
Brecht Van Lommel
3eeacfeb57 Fix: ASAN warnings in light and light tree build
Avoid division by zero and NaN. Should be no functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/132471
2024-12-31 15:22:22 +01:00
Campbell Barton
2edc2393d2 Cleanup: spelling in comments 2024-07-25 10:17:42 +10:00
Weizhen Huang
c816649d85 Cleanup: improve comment regarding Cycles spot light scaling
mentioning increase in noise is a bit misleading because it shouldn't be
noticeable at this scale.
2024-07-23 12:42:30 +02:00
Alaska
90e83175eb Fix #125168: Cycles spot light theata_e can flip with a wide spread
When the spread of a spot light is at it's maximum (180 degrees),
then `atan(tan(theta_e))` could become quite unpredictable due to
a asymtote in the tan function when working with lights with this
spread (because theta_e is `spread * 0.5 = pi/2`).
This lead to issues like theta_e for the spotlight becoming negative,
which lead to rendering errors due to a malformed light tree.

This commit fixes this issue by adding a episilon region around the
troublesome values and sets theta_e to `pi/2` when in that region.

Candidate for backporting to 4.2 and potentially 3.6

Pull Request: https://projects.blender.org/blender/blender/pulls/125172
2024-07-22 17:09:43 +02:00
Campbell Barton
8fdb190278 Cleanup: typos in comments (duplicate words) 2024-07-14 18:55:43 +10:00
Alaska
56bfd56735 Fix: Cycles incorrect rendering of certain negative strength lights
This fixes an issue where lights that make use of constant negative strength
emission shaders would render with the absolute of their strength.

Pull Request: https://projects.blender.org/blender/blender/pulls/118541
2024-02-22 19:06:22 +01:00
Sergey Sharybin
4b217df080 Fix crash in Cycles when cancelling render during light tree building
The recursive building has an early output, which could leave the node
without the requested child initialized, causing the access to the left
child to crash later on in the builder function.

Simply add an extra is-canceled check to avoid access of possibly
non-initialized tree structure.

Pull Request: https://projects.blender.org/blender/blender/pulls/112132
2023-09-08 15:21:54 +02:00
Alaska
462dbe9929 Fix NaN in Cycles light tree bone.axis
Fix `NaN` in the light tree `bcone.axis` that can occur when
normalizing direction vectors of 0 length.

Pull Request: https://projects.blender.org/blender/blender/pulls/110374
2023-07-31 10:56:15 +02:00
Alaska
1261272da7 Cleanup: Simplify get centroid in Cycles light tree builder
`scene->lights[object_id` is already available as `lamp`.

Pull Request: https://projects.blender.org/blender/blender/pulls/110376
2023-07-31 10:40:40 +02:00
Campbell Barton
3889baab4f Cleanup: spelling in comments 2023-07-15 15:54:55 +10:00
Weizhen Huang
482211b7e0 Fix wrong conversion from power to radiance of area lights
The correct conversion factor should be 1 / (pi * area), see #108505

Co-authored-by: Brecht Van Lommel <brecht@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/109153
2023-07-07 17:03:02 +02:00
Campbell Barton
c12994612b License headers: use SPDX-FileCopyrightText in intern/cycles 2023-06-14 16:53:23 +10:00
Sergey Sharybin
5c25277f6c Fix #108374: Sun light linking issue on direct sampling
This is a continuation of a fix from the last week in #108311.
The issue was not fully fixed due to a mistake in the regression
test file.

There are two major things which left to be fixed since the
previous patch:

1. Root nodes can not be shared, even if the local and distant
lights belong to the same light set. If the root node is shared
then the flattening will use the same node index for specialized
trees, which is not a desired behavior.

2. The node type needs to be preserved when a new node is
created for a subset of emitters. This is because tree sampling
in kernel will handle distant and local lights differently for
nodes where there are multiple emitters.

Pull Request: https://projects.blender.org/blender/blender/pulls/108427
2023-05-30 17:39:50 +02:00
Sergey Sharybin
ba3f26fac5 Cycles: light and shadow linking
With light linking, lights can be set to affect only specific objects in the
scene. Shadow linking additionally gives control over which objects acts a
shadow blockers for a light.

Usage:
https://wiki.blender.org/wiki/Reference/Release_Notes/4.0/Cycles

Implementation:
https://wiki.blender.org/wiki/Source/Render/Cycles/LightLinking

Ref #104972
Co-authored-by: Brecht Van Lommel <brecht@blender.org>
2023-05-24 14:11:47 +02:00
Weizhen Huang
8e70ab9905 Fix #107603: queried the area of an empty bounding box 2023-05-11 11:18:12 +02:00
Campbell Barton
6859bb6e67 Cleanup: format (with BraceWrapping::AfterControlStatement "MultiLine") 2023-05-02 09:37:49 +10:00
Weizhen Huang
bfd1836861 Cycles: add instancing support in light tree
Build a subtree for each unique mesh light.

Pull Request: #106683
2023-04-14 19:12:16 +02:00
Weizhen Huang
4c66e0fe61 Fix windows tests failing due to comparison with NaN
which returns false on other platforms but true on windows with fast math
2023-04-05 16:00:03 +02:00
Clément Foucault
4b15f2158f Cleanup: Cycles: LightTree: Fix warning about unused variables 2023-04-04 20:01:55 +02:00
Weizhen Huang
87cbdcbe7c Refactor: move part of light tree logic from #LightManager to #LightTree 2023-04-04 16:24:21 +02:00
Weizhen Huang
e58a05ca68 Refactor: renaming a few light-tree-related variables
primitives -> emitters, `index` -> `node_index`
2023-04-04 16:24:21 +02:00
Weizhen Huang
d872240983 Fix #106528: light tree nodes could have a NaN axis
Caused by collinear vectors not detected due to numerical issue.
2023-04-04 12:40:28 +02:00
Weizhen Huang
1111ce3472 Fix rotate around zero vector in #OrientationBounds 2023-03-23 18:42:39 +01:00
Weizhen Huang
e77b666ae9 Fix normalize zero vector in light tree #OrientationBounds
was assuming such cases are already handled before this function is
called, but seems to be broken on windows and linux. Do
`safe_normalize()` so the tests pass, will check the problem afterwards.
2023-03-23 12:38:25 +01:00
Weizhen Huang
791f35e2c0 Fix rotation axis not normalized in light tree #OrientationBounds 2023-03-23 11:11:54 +01:00
Weizhen Huang
17c8e0d309 Refactor Light Tree to improve readability and efficiency
* Group bounding box, bounding cone and energy to a struct called `LightTreePrimitivesMeasure`
* Add utility functions to add primitives to nodes or buckets
* Precompute the split bucket cost to improve efficiency (about 1.4x expected)

Pull Request: https://projects.blender.org/blender/blender/pulls/105931
2023-03-21 11:06:41 +01:00
Weizhen Huang
23c5e06932 Cycles: build Light Tree in parallel
Push a task to `TaskPool` when more than `MIN_PRIMS_PER_THREAD` primitives are to be processed. The nodes are rearranged in a depth-first order when copied to the device.
Tested with the scene in #105550 on an Apple M1 Ultra (20 cores), about 11x speedup.

Pull Request: https://projects.blender.org/blender/blender/pulls/105862
2023-03-20 18:02:11 +01:00
Weizhen Huang
728694b4e4 Cleanup: use array instead of vector for LightTreeBucket with fixed size 2023-03-17 19:57:04 +01:00
Weizhen Huang
a1a11b08d8 Cleanup: added a bunch of const qualifiers in Light Tree 2023-03-17 19:57:04 +01:00
Campbell Barton
b3625e6bfd Cleanup: comment blocks 2023-03-09 10:39:49 +11:00
Weizhen Huang
b454416927 Cycles: add non-uniform scaling to spot light size
Cycles ignores the size of spot lights, therefore the illuminated area doesn't match the gizmo. This patch resolves this discrepancy.
| Before (Cycles) | After (Cycles) | Eevee
|{F14200605}|{F14200595}|{F14200600}|
This is done by scaling the ray direction by the size of the cone. The implementation of `spot_light_attenuation()` in `spot.h` matches `spot_attenuation()` in `lights_lib.glsl`.
**Test file**:
{F14200728}

Differential Revision: https://developer.blender.org/D17129
2023-02-03 18:51:14 +01:00
Lukas Stockner
39c30f6983 Cycles: Account for negative scale when using one-sided light tree sampling
Differential Revision: https://developer.blender.org/D16952
2023-01-10 02:55:52 +01:00
Brecht Van Lommel
18abc2feaa Fix Cycles light tree not working with negative light strength
Use absolute value of emission as estimate to make this work.

Contributed by Alaska.

Differential Revision: https://developer.blender.org/D16718
2022-12-12 18:28:09 +01:00
Brecht Van Lommel
5270610b29 Fix Cycles uninitialized variables in mesh light sampling
Causing wrong renders and differences between platforms.
2022-12-05 20:20:51 +01:00
Weizhen Huang
ee89f213de Cycles: improve many lights sampling using light tree
Uses a light tree to more effectively sample scenes with many lights. This can
significantly reduce noise, at the cost of a somewhat longer render time per
sample.

Light tree sampling is enabled by default. It can be disabled in the Sampling >
Lights panel. Scenes using light clamping or ray visibility tricks may render
different as these are biased techniques that depend on the sampling strategy.

The implementation is currently disabled on AMD HIP. This is planned to be fixed
before the release.

Implementation by Jeffrey Liu, Weizhen Huang, Alaska and Brecht Van Lommel.

Ref T77889
2022-12-05 16:09:03 +01:00