Commit graph

173 commits

Author SHA1 Message Date
Xury Greer
3e3deb17b6 Cleanup: Spelling in intern/cycles directory
Fixes the following misspellings:

"indicies" -> "indices"
"Remapp" -> "Remap"
"Consine" -> "Cosine"
"Renderman" -> "RenderMan"
"Compution" -> "Compute"

Pull Request: https://projects.blender.org/blender/blender/pulls/164180
2026-09-21 13:14:00 +02:00
Weizhen Huang
cc93b7f5a4 Refactor: Cycles: Separate shader flags and runtime flags
We are running out of bits. Split the original `ShaderDataFlag` into
`ShaderRuntimeFlag`, which is determined by closures in the shader and
set up during rendering, and `ShaderDataFlag`, which is the same for the
whole shader graph and hence determined during shader compilation

The size of `ShaderData` did not change due to padding

Pull Request: https://projects.blender.org/blender/blender/pulls/161856
2026-07-27 19:31:18 +02:00
Brecht Van Lommel
77f344a5ed Fix: Cycles: Mismatch between world importance map and mipmap resolution
When the texture cache evaluates the background shader at a low mipmap level
for next event estimation, it can hit a bright pixel from e.g. very bright
blurred. But in the importance map generated at a higher resolution, the
corresponding pixels may not be bright at all and get a low importance
sampling probability. This leads to significant noise.

To avoid this, clamp the ray differentials so they are at least the ray
differentials used for generating the importance map. This both reduces
noise and mipmap bias. It comes at some extra memory cost, but the
importance map resolution is limited by default and overall it's worth it.

Pull Request: https://projects.blender.org/blender/blender/pulls/159824
2026-06-26 12:34:01 +02:00
Brecht Van Lommel
0baa98866c Refactor: Cycles: Mesh positions include motion, store kernel attribute
Motion is now part of the position attribute. On the kernel side, this
position is now stored as an attribute as well, replacing the previous
motion only attribute.

Pull Request: https://projects.blender.org/blender/blender/pulls/158728
2026-05-27 22:01:25 +02:00
Sergey Sharybin
fde6280480 Refactor: Cycles: Split off visibility from path flags
The issue this change aims to solve is the fact that we are out of bits
in the PathRayFlag. There is a TODO in the code about the fact that we
might need a flag to record primary scatter for volumes. Additionally,
there are plans to introduce visibility flags for the raycast node
rays.

The choice of the underlying type for the PathRayVisibilityFlag keeps
the raycast visibility in mind.

There is now a dedicated type alias to pass visiiblity around in the
kernel. Currently it is 32 bit, keeping in mind possibility of shift
introduced by the shadow catcher. It is possible to limit it to 16,
but then we'd be limited to only 8 visibility bits (which would be
fine until we introduce other flag after the raycast visibility).
Although, it is not really clear it will brings an actual performance
improvement.

The main path state is using 16 to store path visibility, as per the
underlying type of the PathRayVisibilityFlag. It is possible to limit
it to 8 bit to keep state size small until even more ray visibility
bits be needed in the future (the unaligned node bit is not used by the
path visibility).

The shadow path state also needs path visibility to check which path
type it deals with.

Ref !157822
2026-05-27 19:22:53 +02:00
Sergey Sharybin
d61fa843f5 Refactor: Cycles: Rename path visibility flags
Prefix all bits that are mapped to the BVH visibility mask with
`PATH_RAY_VISIBILITY_`.

Should be no functional changes.

Ref !157822
2026-05-27 19:22:53 +02:00
Xavier Hallade
bd83a4506c Cycles: Tune inlining to fix oneAPI performance regression
oneAPI backend had a 4-5% performance regression after 7ee94c067c.
Dropping noinline keyword on few functions recovers previous
performance.

Pull Request: https://projects.blender.org/blender/blender/pulls/158949
2026-05-26 16:11:17 +02:00
Sergey Sharybin
0e8227e590 Cycles: Add Cast Shadows options to world
Implementation is pretty much the same as for actual light objects,
and follows the same limitations w.r.t MIS.

The option is in the World -> Settings -> Surface. The world volume
does not seem to affect scene lighting, and having option under the
surface panel makes the UI look better.

Pull Request: https://projects.blender.org/blender/blender/pulls/156586
2026-04-08 14:15:35 +02:00
Brecht Van Lommel
fa383aa511 Refactor: Cycles: Texture cache miss handling
This adds the various kernel changes needed to handle texture cache
misses on the GPU. For the CPU there is a blocking wait until the pixels
have been loaded from disk. But for GPU we have to restart the kernel.

Pull Request: https://projects.blender.org/blender/blender/pulls/154913
2026-03-27 16:07:06 +01:00
Weizhen Huang
615480dbcb Cleanup: Cycles: Make the notation of Sun Light and Distant Light consistent
Now in Cycles, the term "Sun Light" is used to denote the Sun Light in
Blender UI.

The term "Distant Light" refers to both sun light and background light,
or is occasionally used in places where there is only sun light, but we
would like to add support to background light in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/155133
2026-03-13 11:00:30 +01:00
Weizhen Huang
983cb1f1e1 Cleanup: Cycles: remove unnecessary light linking function
Now that lights are objects, the `light_link_light_match()` function is
not necessary anymore, world is also not `OBJECT_NONE` anymore.

Pull Request: https://projects.blender.org/blender/blender/pulls/155085
2026-03-03 16:54:17 +01:00
Weizhen Huang
e52e5eb06f Refactor: Cycles: Use object index to map to light tree
Now that light is object, we don't need extra light index for mapping it
to the light tree, just use the object index, same as the mesh lights.

Pull Request: https://projects.blender.org/blender/blender/pulls/155084
2026-03-03 16:52:33 +01:00
Weizhen Huang
325277a5ed Cleanup: Cycles: rename shader_flag to visibility_flag
To better match the functionality

Pull Request: https://projects.blender.org/blender/blender/pulls/155081
2026-03-03 16:42:42 +01:00
Brecht Van Lommel
6bbdad08fd Cycles: Use per-corner normals instead of splitting
This is more consistent with Blender and fixes various discrepancies
between Cycles and Blender with sharp edges and mixed flat and smooth
faces. This uses more memory, but is compensated by earlier octahedral
mapping and in the benchmark scenes memory is always the same or lower.

Fix #152812: Mix of flat and smooth faces has incorrect sharp edges
Fix #152496: Smooth faces that share one vertex have bad normals
Fix #100425: Issues with motion blur and autosmooth or edge splitting

Pull Request: https://projects.blender.org/blender/blender/pulls/153836
2026-02-06 19:22:49 +01:00
Brecht Van Lommel
e2ca42eac7 Refactor: Cycles: Store vertex normals as a regular attribute
* Remove tri_vnormal data array
* Add KernelObject.normal_attr_offset for fast lookup
* Apply transform affects normals immediately

Pull Request: https://projects.blender.org/blender/blender/pulls/153836
2026-02-06 19:22:48 +01:00
Campbell Barton
f2871ca16b Cleanup: various spelling corrections in comments & strings 2026-01-28 14:59:34 +11:00
Brecht Van Lommel
4b34743b4e Cycles: Perform direct light shader eval in own kernel
This improves performance by 5-10% for various benchmark scenes and GPU
devices, while on others it's roughly the same. There is a performance
regression with Intel Arc A750 on Linux related to shadow queueing
overhead, that is planned to be fixed separately.

Another goal of this change is to sidestep GPU compiler bugs that seems
more likely to happen with bigger kernels, and to make it easier for the
texture cache to cancel and resume on cache miss.

A new shade_light_nee kernel was added, and shade_light was renamed to
shade_light_forward (following naming for MIS functions). The shade_light_nee
kernel is only used when the light does not have constant emission.

The shade_dedicate_light kernel no longer does any shading. A future
optimization may be to fold this into the intersect_dedicated_light kernel.

LightSample.uv was removed as shading no longer happens immediately. A new
LightPdf was added for the cases where only the pdf is needed, avoiding the
overhead of constructing a full LightSample. There may be more room to
shrink LightSample in future refactors.

The integrate state memory usage is increased by 1 float when not using the
light tree, for the light threshold. All other informating for shading is
reconstructed the shadow ray, including position, normal and uv.

Pull Request: https://projects.blender.org/blender/blender/pulls/152649
2026-01-20 20:34:16 +01:00
Sergey Sharybin
2c4477de04 Cleanup: Cycles, sign conversion
A series of commits which reduces the number of sign conversions
(int <-> uint) in the Cycles kernel.

While it is not expected that the conversion emits any instructions,
it is quite confusing to follow the code and choose proper type.

Additionally, from some development in !151540 it seemed that such
mismatch was responsible for the performance drop in HIP-RT.

Pull Request: https://projects.blender.org/blender/blender/pulls/152009
2025-12-29 12:13:11 +01:00
Weizhen Huang
bb689687a7 Fix #140892: Cycles: equiangular sampling numerical issue
When `delta` is significantly larger than the difference between `tmin`
and `tmax`, the precision of `theta_a` and `theta_b` reduces, resulting
in banding artefacts.

For equiangular sampling, we use uniform sampling to fix this case.

For light tree, we use the equality
atan(a) + atan(b) = atan2(a + b, 1 - a*b).

Pull Request: https://projects.blender.org/blender/blender/pulls/142845
2025-07-23 12:56:11 +02:00
Brecht Van Lommel
0e7a696819 Cleanup: Unused arguments in Cycles kernel
And add back the compiler flag that hid them.

Pull Request: https://projects.blender.org/blender/blender/pulls/139497
2025-05-27 21:30:45 +02:00
Campbell Barton
d616c87d03 Cleanup: spelling in comments (make check_spelling_*) 2025-03-21 11:51:50 +11:00
Brecht Van Lommel
48398b223b Cleanup: Fix various divisions by zero reported by ASAN
Pull Request: https://projects.blender.org/blender/blender/pulls/135326
2025-03-06 22:34:23 +01:00
Xavier Hallade
a5d8bd2e29 Cycles: Drop inline hint on light_tree_pdf
Dropping the inlining hint for `light_tree_pdf` and reverting to the
default inlining thresholds for DPC++ compiler gives a ~4% speedup on
classroom and other scenes on Arc B580.

Pull Request: https://projects.blender.org/blender/blender/pulls/135042
2025-02-26 20:14:05 +01:00
Brecht Van Lommel
655ccf1d7a Fix #135086: Light ray visibility not taken into account without light tree
Re-enable tests that were temporarily disabled for this.

Caused by #134846, e813e46327
2025-02-25 17:24:04 +01: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
Alaska
58b7543ede Fix #132322: Artifacts in Cycles volume rendering with Light tree on some devices
In a previous commit (1), adjustments to light tree traversal were made
to try and skip distant lights when deciding which light to sample
while within a world volume.

The skip wasn't implemented properly, and as a result distant lights
were still included in the light tree traversal in that sitaution.
And due to the way the skip was implemented, there were some
unintialized variables used in the processing of the distant lights
importance which caused artifacts on some platforms.

This commit fixes this issue by reverting the skip of distant lights
in that situation.

(1) blender/blender@6fbc958e89

Pull Request: https://projects.blender.org/blender/blender/pulls/132344
2025-01-22 05:50:32 +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
d0c2e68e5f Refactor: Cycles: Automated clang-tidy fixups in Cycles
* Use .empty() and .data()
* Use nullptr instead of 0
* No else after return
* Simple class member initialization
* Add override for virtual methods
* Include C++ instead of C headers
* Remove some unused includes
* Use default constructors
* Always use braces
* Consistent names in definition and declaration
* Change typedef to using

Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:22:55 +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
3c2a6fbb9c Refactor: Cycles: Use nullptr instead of NULL
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:22:43 +01:00
Thomas Dinges
1be75e86aa Cleanup: replace floatX_to_floatY() with make_floatY()
Now that function overloads are usable on all GPUs, replace the former explicit functions.

Pull Request: https://projects.blender.org/blender/blender/pulls/132067
2024-12-19 09:41:55 +01:00
Alaska
8e6a981487 Fix #131927: Cycles: Reduce uncertain light tree traversal in scenes with one distant light
When a scene contains distant lights and local lights, the first step
of the light tree traversal is to compute the importance of
distant lights vs local lights and pick one based on a random number.

In the specific case of when there is only one distant light,
the line of code that had been changed in this commit
effectively reduced to:
`min_importance = fast_cosf(x) < cosf(x) ? 0.0 : compute_min_importance`

And depending on the hardware, compiler, and the specific value being
tested, different configurations could take different code paths.

This commit fixes this issue by turning the comparison into
`fast_cosf(x) < fast_cosf(x)`.

---

Why does `cos_theta_plus_theta_u < cosf(bcone.theta_e - bcone.theta_o)`
reduce to `fast_cos(x) < cos(x)` in this specific case?

- `cos_theta_plus_theta_u` is computed as
`cos_theta * cos_theta_u - sin_theta * sin_theta_u`
- `cos_theta` is always 1.0 in the case of a single distant light.
- `cos_theta_u` is computed earlier as `fast_cosf(theta_e)` in
`distant_light_tree_parameters()`
- `sin_theta` is zero, and so that side of the equation doesn't matter.

This reduces `cos_theta_plus_theta_u` to `fast_cosf(theta_e)`.

`cosf(bcone.theta_e - bcone.theta_o)` reduces to `cosf(bcone.theta_e)`
because for the case of a single distant light `theta_o` is always 0.

Pull Request: https://projects.blender.org/blender/blender/pulls/131932
2024-12-17 10:51:43 +01:00
Weizhen Huang
93a34b1077 Refactor: Cycles: add helper struct Interval
To improve readability

Pull Request: https://projects.blender.org/blender/blender/pulls/130156
2024-11-12 12:06:09 +01:00
Weizhen Huang
90ed91dfdb Cleanup: Cycles: Add Kernel prefix to light tree bounding shapes
BoundingBox -> KernelBoundingBox
BoundingCone -> KernelBoundingCone

Pull Request: https://projects.blender.org/blender/blender/pulls/130141
2024-11-11 17:13:55 +01:00
Weizhen Huang
e9593a6619 Cleanup: Cycles: update light tree paper link
The original one was expired
2024-11-11 15:46:52 +01:00
Weizhen Huang
81590dab5e Merge branch 'blender-v4.3-release' 2024-10-29 18:01:41 +01:00
Weizhen Huang
219e655119 Fix #129420: precision issue in light tree distant light angle
In volume segment, the minimal angle formed by the emitter bounding cone
axis and the vector pointing from the cluster centroid to any point on
the ray is computed via `dot(bcone.axis, point_to_centroid)`, see Fig.8.
in paper.
For distant light this angle is 0, but due to numerical issues this is
not always true. Therefore explicitly assign `-bcone.axis` to
`point_to_centroid` in this case.

Pull Request: https://projects.blender.org/blender/blender/pulls/129489
2024-10-29 18:00:59 +01:00
Alaska
356482ecb5 Cleanup: Fix ambiguous Unicode character warning in Cycles tree.h
Gitea would complain the apostrophe in one of the code comments in
tree.h was an ambiguous Unicode character. So fix it by swapping it
for a more common apostrophe type.
2024-10-16 21:21:57 +13:00
Alaska
84bab7f300 Fix #126592: Cycles light tree subtended angle not covering the entire bounding box
Use a bounding sphere instead of the corners of a bounding box to
compute the subtended angle of a light tree node.

Using the corners of the bounding box was an underestimate in some
scenes, causing some light tree nodes being incorrectly skipped.

Using the subtended angle of a bounding sphere is an overestimate, but
it covers the entire node and would not skip any valid contribution,
and no other reliable algorithm to compute the minimal enclosing angle
is known to us.

We expect some increase in noise due to overestimation, but this has
not been observed yet, in our benchmark scenes only a difference in
noise is visible.

Thanks to Weizhen for the suggestion to use the bounding sphere.

Pull Request: https://projects.blender.org/blender/blender/pulls/126625
2024-08-28 11:53:53 +02:00
Weizhen Huang
6fbc958e89 Fix: Cycles Light Tree gives low weight to distant lights in large volume
The original paper only considers the minimal distance of the cluster to
the ray, not the interval length, resulting in low weight for distant
lights that have large influence over a long distance.
This commit modifies the measure by considering `theta_b - theta_a` for
local lights and the ray length `t` for distant lights.

Pull Request: https://projects.blender.org/blender/blender/pulls/123537
2024-06-24 12:48:08 +02:00
Weizhen Huang
2ddc936cbb Cleanup: simplify computation in Cycles area light sampling
`diff` in numerator and denominator cancels out, except for the signs,
which we know beforehand since `x1 > x0`, `y1 > y0`

Pull Request: https://projects.blender.org/blender/blender/pulls/122740
2024-06-04 23:37:48 +02:00
Lukas Stockner
fbc770d58b Cycles: Fallback to area PDF when spherical rectangles are too small
This fixes #69535 and #98930.

We use a equi-solid-angle sampling algorithm for rectangular area lights,
but it is not particularly robust for small area lights (either small
in general and/or small because it's being viewed from grazing angles).

The actual sampling part is fine since it just gets clamped into the
valid area anyways, and the difference isn't notable for small lights.

However, we also need to compute the solid angle to get the sampling PDF,
and that computation is quite sensitive to numerical issues for small
values.

Therefore, this commit adds a fallback path for small values, which instead
uses the classic equi-area sampling PDF term times the area-to-solid-angle
Jacobian term. This approximation assumes that all points on the light have
the same distance and angle to the sampling point, which is of course not
strictly the case, but it's close enough for small area lights and better
than failing altogether.

Pull Request: https://projects.blender.org/blender/blender/pulls/122323
2024-06-04 01:55:26 +02:00
Lukas Stockner
a5dc233aa2 Cycles: Tweak area light sampling to improve numerical robustness
Reformulates some terms in the equi-solid-angle rectangle sampling code to
handle small area lamps better, and allows for some rounding error in the
check whether the sampled position is inside the area light.

Pull Request: https://projects.blender.org/blender/blender/pulls/122323
2024-06-04 01:55:25 +02:00
Weizhen Huang
296ac0e9ef Cycles: improve light tree with large spot blend
In the original paper, the falloff inside `bcone.theta_e` is assumed to
be `pi/2`, which is too large for spot light and resulted in an
overestimation near the cone boundary.
To address this issue, attenuate the energy of a spot light using the
minimal possible angle formed by the light axis and the shading point
when traversing the light tree.

Ref: #122362

Pull Request: https://projects.blender.org/blender/blender/pulls/122667
2024-06-03 23:33:29 +02:00
Lukas Stockner
392b84f879 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.

Pull Request: https://projects.blender.org/blender/blender/pulls/119224
2024-05-23 02:27:48 +02:00
Weizhen Huang
0c9ce4ba4f Refactor: handle MIS weight in lower-level functions
it is difficult to keep in mind when MIS weight is needed, better to
handle this logic in the lower-level functions.
This reduces code duplication in many places.
2024-04-17 18:49:00 +02:00
Weizhen Huang
418acfe8bb Cleanup: remove unused function parameters
This is not a complete list of all the unused parameters in kernel, but
those I touch often, so I am more confident that it's safe to delete them.
2024-04-17 18:49:00 +02:00
Weizhen Huang
68253b4937 Fix: Cycles volume light tree using wrong point to compute uncertainty angle
it is not clear from which point the `cos_theta_u` should be computed in
volume segment, so the original implementation was mixing the closest point
and the point where the minimal angle is formed.
Use the closest point on segment as a conservative measure.

Pull Request: https://projects.blender.org/blender/blender/pulls/119965
2024-03-27 15:06:05 +01:00
Weizhen Huang
72780c3769 Fix: Cycles light tree assertion failing on Intel Mac
in the test scene `all_light_types_in_volume.blend`, `theta - theta_o -
theta_u` is slightly above the threshold. Even if we do a strict check
with `acos` on the failing cases, it will go to the other branch and
deliver a result which is also 1.0f. Better to relax the threshold.
2024-03-27 13:46:57 +01:00