Commit graph

925 commits

Author SHA1 Message Date
Xavier Hallade
1b20a88e97 Fix: Cycles: oneAPI: Performance regression from DPC++ upgrade
The intel/llvm 7.1 upgrade is giving a large performance regression in
shade_surface kernel on Intel GPUs. I've root-caused it down to a slight
shift in private memory layout due to slightly different inlining.

To fix both this regression and overall performance sensitivity on
private memory layout, that can happen with any code change beyond the
DPC++ upgrade, I'm forcing ShaderData and svm's stack alignments to 64
bytes.

Pull Request: https://projects.blender.org/blender/blender/pulls/164411
2026-09-28 20:11:37 +02:00
Brecht Van Lommel
0e9da840ab Fix: Cycles: Crash with kernel compilation without hair or SSS
Need to skip BSDF data properly then. Also better handle hair and point
info node in such cases.

Issue introduced in 7ee94c067c.

Pull Request: https://projects.blender.org/blender/blender/pulls/164137
2026-09-19 23:14:16 +02:00
Brecht Van Lommel
1d8aeab8c0 Fix: Cycles: Crash with SSS legacy random walk and emission
Issue introduced in 7ee94c067c.

Pull Request: https://projects.blender.org/blender/blender/pulls/164137
2026-09-19 23:14:16 +02:00
Sergey Sharybin
071bea748b Fix: Cycles access to radiance attribute for gsplats
This commit fixes the behavior when the shader graph accesses "radiance"
attribute in the case when the geometry has such attribute. The desired
behavior is to output the stored attribute instead of doing the runtime
radiance+base + spherical harmonics evaluation.

This is how OSL backend behaved prior to this change. So in a way it
fixes discrepancy between SVM and OSL.

Pull Request: https://projects.blender.org/blender/blender/pulls/164039
2026-09-18 19:31:19 +02:00
Brecht Van Lommel
c737da4117 Fix #163829: Cycles: Crash with bump from displacement and emission
The changes in 7ee94c067c did not properly handle the case where SVM
nodes evaluation has some feature disabled. The full SVM node data must
always be skipped.

Pull Request: https://projects.blender.org/blender/blender/pulls/164019
2026-09-17 16:40:39 +02:00
Sergey Sharybin
819d52f3d2 GSplat: Initial rendering support for Cycles
Based on the "Stochastic ray tracing of transparent 3D Gaussians" paper
by Xin Sun et. al. The basic idea: perform stochastic intersection with
the Gaussian splat based on its transparency.

Gaussian splats are implemented as a dedicated primitive type, but it
shares the same layout for position and radius as points, so a lot of
existing functions (positions, attributes, etc) work for both points
and splats.

For the Embree and hardware intersection it is implemented as a custom
primitive type.

The choice of using bounding spheres mainly comes from a balance between
performance and memory usage. More ideal would be to use OBB, but it is
not supported for custom primitive types in Embree and GPU HW-RT on all
backends.

There is a known limitation that comes from the fact that the datasets
are trained in sRGB space and Cycles work in Linear space: areas with
low opacity and high radiance render noticeably differently from the
ground-truth implementation.

Ref #159470

Pull Request: https://projects.blender.org/blender/blender/pulls/163103
2026-09-16 16:52:10 +02:00
Brecht Van Lommel
61763859fb Fix #161943: Cycles HIP pthread_create crash
This appears to have been caused by invalid use of assert() instead of
kernel_assert() in the kernel. I don't think it's actually hitting that
assert, but maybe it generated an unsupported instruction or something
along those lines?

The one that caused the actual problem is in svm/convert.h. I changed
more instances that are currently CPU only but risk becoming enabled on
the CPU with future code changes.

Thanks to Sahar A. Kashi for finding this.

Pull Request: https://projects.blender.org/blender/blender/pulls/163970
2026-09-16 00:00:00 +02:00
Alex Fuller
3ff1f508e6 Cycles: Fallback value for missing image or attribute in shader
The implements internal support in Cycles for fallback values when an
attribute or image texture is missing in a shader node. It is not yet
exposed in Blender shader nodes.

This is useful to provide an appropriate default value when a shader is
used across objects with different attributes, or when UDIMs don't cover
the entire UV space.

Pull Request: https://projects.blender.org/blender/blender/pulls/162785
2026-09-15 19:45:36 +02:00
Jacques Lucke
ba82476ade Shader Nodes: support Integer Math node in EEVEE and Cycles
This adds the Integer Math node to shader nodes. It's the same node that
can already be used in Geometry Nodes and the Compositor.

While creating the regression test, I noticed that the integer math
implementation was a bit broken:
* The integer modulo (`%`) operator on the GPU is undefined for negative
  divisors (the added regression test showed that the behavior is not
  consistent across platforms).
* Use integer power function instead of using float implementation with
  casts.

The MaterialX implementation is omitted for now. I didn't look into it
in detail yet but for the Boolean Math node (#162798) it seemed like
some more work is needed there to support this type.

Pull Request: https://projects.blender.org/blender/blender/pulls/163805
2026-09-14 10:36:19 +02:00
Jacques Lucke
6c74e82ecb Shader Nodes: support Boolean Math node in EEVEE and Cycles
This adds the Boolean Math node to shader nodes. It's the same node that
can already be used in Geometry Nodes and the Compositor.

This also fixes the conversion from other types to boolean values so that
it it consistent across different node tree types. Cycles doesn't have
native support for booleans currently (it encodes them in integers), so
for now this conversion is entirely handled in the inliner.

The MaterialX implementation is omitted for now because it seems to need
more work to properly integrate booleans (right now it appears to ignore
all links going from a float to a boolean socket for example).

Pull Request: https://projects.blender.org/blender/blender/pulls/162798
2026-09-12 14:43:16 +02:00
Brecht Van Lommel
4fa3075d21 Fix: Cycles: Quaternion attribute alpha differs in derivative path
Use make_float4 in both paths, as it swizzles components.

This issue was introduced in 0636c92036.

Pull Request: https://projects.blender.org/blender/blender/pulls/163579
2026-09-07 14:34:08 +02:00
Weizhen Huang
0fdaf6be0e Cycles: Support anisotropic glass
The functionality is already there, just need to set it up

Implemented for Principled BSDF and Glass BSDF.

Pull Request: https://projects.blender.org/blender/blender/pulls/163343
2026-09-04 10:02:05 +02:00
Sergey Sharybin
a4cdca016e Cleanup: Cycles: Consistently call packed spherical harmonics rest
The pack only contains bands 1 to 3. The evaluation function has
been renamed as part of the original review. It makes sense to be
consistent, although a bit more verbose.

Pull Request: https://projects.blender.org/blender/blender/pulls/163446
2026-09-03 11:27:09 +02:00
Sergey Sharybin
79d6d1659c Cycles: Add spherical harmonics attribute
Includes possibility of adding spherical harmonics on geometry, as well
as includes spherical harmonics evaluation.

Spherical harmonics are stored quantized to 8 bit integer, and always
use degree 3. The reason for the limited degree is the memory: degree
3 requires relatively small amount of coefficients (45 int8_t, which
is similar to how realtime renderers pack them into float3x4). Going
higher dimension adds a lot more coefficients to store, and so far it
doesn't seem there are gsplat data-sets that are trained to a degree
higher than 3.

The attribute is currently unused. It is preparation work foe the
gsplat project to make reviews easier.

Ref #159470

Pull Request: https://projects.blender.org/blender/blender/pulls/163409
2026-09-02 16:43:18 +02:00
Sergey Sharybin
0636c92036 Cycles: Add Quaternion attribute type
The main goal is to bring a bit of structure to the use of quaternions
in the Cycles kernel.

Prior to this change there was no dedicated quaternion type and float4
was used instead, and quaternions are stored as (x, y, z, w) matching
naming between the quaternion and float4 fields. However, Blender uses
(w, x, y, z) quaternion order for attributes, which is different from
what Cycles uses. Without dedicated type this either leads to different
quaternion orders depending whether it comes from attribute, or makes
it intrinsically not possible to use implicit sharing.

This change introduces Cycles Quaternion type which is compatible with
Blender attribute math::Quaternion in both layout and alignment, making
it possible to benefit from implicit sharing and use a nice structure
in the kernel.

This change does not modify the existing quaternion usage in the kernel
which is currently used for transform decomposition and interpolation.

There is currently no SIMD for the Quaternion type, which allows to
avoid any special alignment requirement and share attributes with
Blender, but performance might not be ideal.

This attribute type will be used for representing gaussian splat
rotation.

The attribute access and interpolation matches behavior prior to this
change. Added some basic tests for quaternion attribute access for RGB
and alpha, mesh and volume attributes.

Ref #159470

Pull Request: https://projects.blender.org/blender/blender/pulls/163342
2026-09-02 09:08:34 +02:00
Weizhen Huang
df6b084c49 Fix: Shader: wrong coat albedo for fractional coat weight
According to OpenPBR spec v1.1.1 Eq. (9), the correct layering for a
coated substrate is
$$f_\mathrm{layer} = f_\mathrm{coat} + T_\mathrm{coat}(1  - E_\mathrm{coat})f_\mathrm{sub}.$$
For fractional coat weight, we apply Eq. (14), and it becomes
$$
\begin{aligned}
f_\mathrm{weighted-layer}&=(1-w_\mathrm{coat})f_\mathrm{sub}+w_\mathrm{coat}f_\mathrm{layer}\\
&=(1-w_\mathrm{coat})f_\mathrm{sub}+w_\mathrm{coat}(f_\mathrm{coat} + T_\mathrm{coat}(1  - E_\mathrm{coat})f_\mathrm{sub})\\
&=w_\mathrm{coat}f_\mathrm{coat}+(1-w_\mathrm{coat}(1-T_\mathrm{coat}(1-E_\mathrm{coat})))f_\mathrm{sub}
\end{aligned}
$$
Here, \(E_\mathrm{coat}\) does not contain the coat weight nor the
overall weight of the coated closure \(w_\mathrm{layer}\), but our
current way of using `bsdf_albedo()` contains both weight, after which
we apply \(T_\mathrm{coat}\), which is wrong.

To fix this issue, we allow RGB weight for the layer operation, and
directly return a albedo of

$$
A_\mathrm{coat} = w_\mathrm{layer}w_\mathrm{coat}(1-T_\mathrm{coat}(1-E_\mathrm{coat}))
$$
Thus, when we apply the layer operation, we get
$$
\begin{aligned}
&w_\mathrm{layer}\mathrm{layer}(S_\mathrm{sub},S_\mathrm{coat},w_\mathrm{coat})\\
=&w_\mathrm{layer}(1-w_\mathrm{coat})S_\mathrm{sub}+w_\mathrm{layer}w_\mathrm{coat}\mathrm{layer}(S_\mathrm{sub},S_\mathrm{coat})\\
=&w_\mathrm{layer}(1-w_\mathrm{coat})S_\mathrm{sub}+w_\mathrm{layer}w_\mathrm{coat}S_\mathrm{coat} + (w_\mathrm{layer}w_\mathrm{coat}-A_\mathrm{coat})S_\mathrm{sub}\\
=&w_\mathrm{layer}w_\mathrm{coat}S_\mathrm{coat}+(w_\mathrm{layer}-A_\mathrm{coat})S_\mathrm{sub},
\end{aligned}
$$

Which matches the equation for \(f_\mathrm{weighted-layer}\).

A modification to the sheen BSDF was needed to make it not tint the sub
layers.

Pull Request: https://projects.blender.org/blender/blender/pulls/162471
2026-08-26 12:11:08 +02:00
Weizhen Huang
2f61e87ae2 Fix: Cycles: wrong flag for testing closure for emission layering
When the path is being terminated after the current vertex, we also
don't allocate closures, but we still need the weight for layering.
2026-08-26 12:11:07 +02:00
Weizhen Huang
e5e51a6863 Cleanup: Cycles: Reduce duplication in SVM/OSL sheen setup
Also use the MaterialX-compatible `sheen_bsdf()` internally for the old
`sheen()` OSL closure, as they are essentially the same.

Should remove `sheen()` in 6.0
2026-08-26 12:11:07 +02:00
Weizhen Huang
f15daf81bf Cycles: Add dispersion to Principled BSDF
Dispersion is defined by two parameters:
Abbe Number and Dispersion Scale.

This corresponds to OpenPBR v1.1.1

Pull Request: https://projects.blender.org/blender/blender/pulls/162041

Note: dispersion is temporarily disabled when using MNEE (shadow caustics) on oneAPI, due to a compiler bug. Waiting for a fix from the oneAPI side.

![prism.png](/attachments/219c3966-b39d-4846-991b-976f84f83081)
Co-authored-by: Sebastian Herholz <sebastian.herholz@gmail.com>
2026-08-18 11:03:49 +02:00
Sergey Sharybin
a70b34065d Refactor: Cycles: Make kernel_features 64bit
This change adds 32 more bit to store kernel features.

While for a short term it might be possible to make a space for one or
two extra bits, it seems going 64bit is inevitable.

Expanding the field to 64bit might introduce some slowdown due to less
optimal cache, but so is consolidation of existing flags could also
lead to performance drop in certain configurations.

The main tricky part of the change is Metal where function constants
are used to store kernel_features, and 64bit constants are only
available on macOS 12. There is a runtime check for it. On older macOS
versions the flags are stored as a pair of 32bit values. It is slower,
but there are unlikely to be many Cycles users on macOS 11.

Ref #159470

Pull Request: https://projects.blender.org/blender/blender/pulls/162737
2026-08-18 10:41:27 +02:00
Weizhen Huang
0b2e8f3562 Refactor: Cycles: Add struct to encompass both reflectance and transmittance
to simplify the code and make future changes easier

Pull Request: https://projects.blender.org/blender/blender/pulls/161854

---------

Co-authored-by: Sebastian Herholz <sebastian.herholz@gmail.com>
2026-08-17 17:13:12 +02:00
Jacques Lucke
216b62e05c Nodes: new Get Vector Component node
This adds a new simple node which retrieves the X, Y or Z component of a vector
by index. This is simpler and more efficient than using workarounds like using a
Separate XYZ with an Index Switch node.

The original motivation for this node came from #149091 where we wanted to
support this using expressions (`vector[i]`).

Co-authored-by: Tibo Stans <stanstibo@gmail.com>
2026-08-12 17:22:43 +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
dfe96383c9 Merge branch 'blender-v5.2-release' 2026-07-03 13:37:55 +02:00
Brecht Van Lommel
00c5985862 Fix #160980: Cycles area light texture using Generated coordinates is broken
Regression from dcac328db3. svm_node_attr_init() set offset to 0 which
doesn't work with is_attribute_found() introduced in that commit, it
expects ATTR_STD_NOT_FOUND.

I traced all users of svm_node_attr_init() and found they all check
either (element & ATTR_ELEMENT_X) or is_attribute_found()` which both
work.

Pull Request: https://projects.blender.org/blender/blender/pulls/161012
2026-07-03 13:31:56 +02:00
Weizhen Huang
ba40cdca1c Cycles: Skip evaluating emission for volume extinction
Removes a TODO in the code.
2026-06-25 12:45:16 +02:00
Weizhen Huang
f2af4767d6 Cycles: Skip evaluating volume emission for shadows
It was already applied to principled volume and volume coefficients, but
not to the emission BSDF.
2026-06-25 12:45:16 +02:00
Brecht Van Lommel
7c7094b4e1 Merge branch 'blender-v5.2-release' 2026-06-23 17:58:33 +02:00
Brecht Van Lommel
8842e9b8c9 Fix #160400: Cycles texture cache HDRI background broken with mapping
Add missing derivative SVM node for built-in texture coordinate mapping
of texture nodes. Because this mapping is built into the node, not only
were the derivatives missing but SVM stack memory was read uninitialized.

An existing mipmap test was updated to include this type of mapping.

Pull Request: https://projects.blender.org/blender/blender/pulls/160518
2026-06-23 17:57:05 +02:00
Brecht Van Lommel
a176b84a1b Merge branch 'blender-v5.2-release' 2026-06-23 12:50:34 +02:00
Brecht Van Lommel
406577e0d6 Fix #160052: Cycles: Performance regression with CUDA + Blackwell + BVH2
Store positions as separate arrays again. This appears to give better
memory access patterns or layout. This was a regression from fc9917352b
and 0baa98866c.

This is a relatively simple change, rerouting the position attribute to
dedicated arrays, still including motion steps in the same array. The rest
of the refactor is preserved.

Pull Request: https://projects.blender.org/blender/blender/pulls/160110
2026-06-23 12:33:04 +02:00
Miguel Pozo
6e7a0eee32 Cycles: Raycast Visibility Toggle
Cycles implementation of #157799.
Allows removing objects from Raycast Node queries.

Adds `PathRayVisibilityFlag::PATH_RAY_VISIBILITY_RAYCAST` .
OSL adds a new `__raycast__` traceset.

Pull Request: https://projects.blender.org/blender/blender/pulls/158816
2026-06-17 20:37:50 +02:00
Weizhen Huang
377ce8196e Merge branch 'blender-v5.2-release' 2026-06-09 17:35:41 +02:00
Weizhen Huang
8d7da77bfe Fix: Cycles: Add missing padding in SVMInputInt
_No response_

Pull Request: https://projects.blender.org/blender/blender/pulls/159854
2026-06-09 17:33:53 +02:00
Weizhen Huang
d4ee9b9e79 Cycles: Improve smooth thin glass shadow
By allocating transparent BSDF for non-camera rays when roughness is
sufficiently low

Pull Request: https://projects.blender.org/blender/blender/pulls/159798
2026-06-09 17:33:26 +02:00
Raiko
f14783d511 Nodes: Optimize Four Color Mix Modes
The geo nodes implementations of the `mix`, `addition`, `multiplication`
and `subtraction` color mix modes are both faster and have better
numerical properties than the ones we use in Cycles, OSL and EEVEE.

This PR ports the geo nodes implementations of those color mix modes
to Cycles, OSL and EEVEE.

Additionally, the SVM mix function implementation is templatized and
a new function called "endvalue_preserving_mix" is added for the
alternative variant of linear interpolation.

Pull Request: https://projects.blender.org/blender/blender/pulls/158022
2026-06-05 11:54:48 +02:00
Brecht Van Lommel
3e66796803 Cleanup: Cycles: Remove redundant rgb_to_spectrum
Pull Request: https://projects.blender.org/blender/blender/pulls/159334
2026-06-01 14:58:43 +02:00
Weizhen Huang
1870573666 Refactor: Cycles: Extract function to adjust thin film ior at backface
Will be used for OpenPBR too, improve comment to help understanding

Pull Request: https://projects.blender.org/blender/blender/pulls/159223
2026-06-01 13:53:15 +02:00
Weizhen Huang
56331f36d9 Fix #158969: Cycles: Principled Emission not attenuated by coat/sheen in NEE
Allocate BSDF closures locally to attenuate the weight for emission

Pull Request: https://projects.blender.org/blender/blender/pulls/159275
2026-05-29 15:47:25 +02:00
Weizhen Huang
d5e1b256ae Fix: Cycles: Principled BSDF Emission should be Spectrum instead of float3
Pull Request: https://projects.blender.org/blender/blender/pulls/159209
2026-05-29 10:05:35 +02:00
Weizhen Huang
ee2fe3cc52 Refactor: Cycles: Extract emission component from Principled BSDF
OpenPBR can also have emission, so the compiler hint for optimizing out
other BSDFs doesn't work anymore.
Instead, we extract the function to compute emission, and share it when
evaluating BSDF and surface emission
2026-05-29 10:05:34 +02:00
Weizhen Huang
53a0e4c271 Refactor: Cycles: Only read required Principled BSDF closure data 2026-05-29 10:05:34 +02:00
Brecht Van Lommel
fc9917352b Refactor: Cycles: Hair/Point positions include motion, kernel attribute
Motion is now part of the position attribute. On the kernel side, a
combined position + radius attribute is now stored, replacing the
previous motion only attribute.

Legacy motion attributes are now removed.

Pull Request: https://projects.blender.org/blender/blender/pulls/158728
2026-05-27 22:01:25 +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
Brecht Van Lommel
7933f92f89 Refactor: Cycles: Use packed_float3 for arrays, accessors for geometry data
Use packed_float3 instead of float3 for geometry positions and various
other arrays.

Add and use unified accessor methods get_position() and get_radius() for
all geometry, as well as num_verts(), num_points() and num_keys().

Pull Request: https://projects.blender.org/blender/blender/pulls/158728
2026-05-27 22:01:24 +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
0ed5cd6bfc Refactor: Cycles: Introduce type name alias for visibility
Currently matches the `uint` that is used everywhere. Intended to
be used everywhere in the kernel and in the host where visibility
is passed around.

It might become a narrower type in the future if visibility fits
into 8 bits (it could become uint16_t then, to have space for the
shadow catcher shifts).

Should be no functional changes,

Ref !157822
2026-05-27 19:22:53 +02:00
Sergey Sharybin
dfca81b57e Refactor: Cycles: Use bit operations for visibility manipulation
Should be no functional changes.

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
Weizhen Huang
6e2b342c9f Render: Add thin wall mode in Principled BSDF
- Thin glass:
An infinitesimally thin sheet of dielectric, approximated by a reflected
lobe and a trasmitted lobe, the respective weights of both lobes are
analytically computed by summing up infinite geometric series that
account for internal reflections.

- Thin subsurface:
An infinitesimally thin sheet of dense scattering material, approximated
by a diffuse lobe and a translucent lobe, the respective weights of both
lobes are given by subsurface anisotropy, with specifies the relative
amount of backward and forward scattering.

Co-authored-by: Jesse Yurkovich <jesse.y@gmail.com>

Pull Request: https://projects.blender.org/blender/blender/pulls/157469
2026-05-22 12:53:43 +02:00