Commit graph

46 commits

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

"equi-angular" -> "equiangular"
"otheriwse" -> "otherwise"
"implememted" -> "implemented"
"tranmissitance" -> "transmittance"
"derivates" -> "derivatives"
"cauzed" -> "caused"
"unsinged" -> "unsigned"
"stochastical" -> "stochastic"
"LighTree" -> "LightTree"
"stdilb" -> "stdlib"
"colospace" -> "colorspace"
"evaulated" -> "evaluated"

Pull Request: https://projects.blender.org/blender/blender/pulls/163850
2026-09-14 12:09:40 +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
Brecht Van Lommel
41e2d2dadd Fix #162183: Cycles texture cache broken for textures larger than 2^31 px
Fix integer overflows that were causing this, in the kernel and in tx
generation. The overflow caused both wrong render results and slowness
due to too many tiles being loaded due to wrong derivatives.

Also fix an additional overflows in CPU image sampling without the cache.

Pull Request: https://projects.blender.org/blender/blender/pulls/162195
2026-08-05 21:35:48 +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
518c2cf35c Fix #159135: Cycles texture cache shifts textures with odd pixel dimensions
This was supposed to round down instead of up, to match logic for
generating the tx file.

Pull Request: https://projects.blender.org/blender/blender/pulls/159178
2026-05-28 00:44:07 +02:00
Brecht Van Lommel
c6d110e8ec Cycles: Texture cache eviction for final renders
Evict unused texture cache tiles between render tiles and multiviews, to
reduce memory usage. Tiles that were loaded but not accessed during the
previous render tile are freed before the next tile begins rendering.

A per-tile access state byte tracks three values (NONE, REQUESTED, USED)
and is used both to drive tile loading from cache misses and to decide
which loaded tiles can be evicted at tile boundaries.

Cache eviction is automatically enabled, but there is a debug option to
disable it. There is also an debug option to preserve a specified amount
of unused image texture memory to aoid avoid trashing unnecessarily in
simple cases. It increases peak memory usage to render faster, however
in tests on a Macbook M3 it did not seem worth it. But left in to
experiment on other devices and scenes.

Pull Request: https://projects.blender.org/blender/blender/pulls/157244
2026-04-20 17:51:59 +02:00
Brecht Van Lommel
9c736864af Refactor: Cycles: Generalize tile request mask to tile access state
To extend it with a USED state for cache eviction later.

Pull Request: https://projects.blender.org/blender/blender/pulls/157244
2026-04-20 17:51:59 +02:00
Brecht Van Lommel
b68c056e2c Cycles: Texture cache tiled image loading
* Detect tx files associated with images
* Add tiled image loading in ImageCache and OIIOImageLoader
* Pad tiles for fast hardware texture filtering
* Kernel side tile mapping with stochastic mip selection
* Statistics support for mipmaps and tiles loaded

Ref #68917

Pull Request: https://projects.blender.org/blender/blender/pulls/154913
2026-03-27 16:07:06 +01:00
Weizhen Huang
f2394a431e Cycles: Support automatic differentiation of shader nodes in SVM
This is an internal change preparing for the texture cache. Only implemented
for surfaces, and currently supports the following nodes:

- Geometry
- Tangent
- Mapping
- Attribute
- Texture Coordinate
- Environment Texture
- Image Texture
- Vector math
- UV Map
- Combine/Separate XYZ
- Bump

This has some impact on GPU rendering performance. Various changes were
made to optimize this, but rendering can still be a few % slower on some
GPUs. Some of the optimizations done:

* Use different node types enum for derivative nodes, consecutive to ensure the
  jump table works.
* Template various SVM derivative nodes to separate them from the
  non-derivative case, and avoid using dual types in those implementations.
* Use template on return type for stack_store and stack_load to make the above
  easier to implement.
* Use template on return type of primitive attribute reading to make derivative
  and non-derivative variations.
* Unify derivative and bump dx/dy nodes. Now it's a single derivative node
  that handles both cases.
* Derivative nodes are disabled in volume shaders for now.
* Tweak inlining on a few functions.

Co-authored-by: Brecht Van Lommel <brecht@blender.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/155706
2026-03-16 18:20:54 +01:00
Brecht Van Lommel
1ffb43fc69 Refactor: Cycles: Move UDIM code out of SVM, refactor ImageHandle
Refactor ImageHandle to used pointers to a new ImageSlot istead of slot
indices. ImageSlot has subclasses ImageSingle and ImageUDIM, for
individual images and UDIMs. ImageUDIM has a list of handles for
ImageSingle.

UDIM tile lookup was moved out of SVM and OSL code, and is now shared.

Early loading of images for displacement and volumes was refactored.
Now a set of ImageSingle pointers is collected, which are then loaded
by the image manager.

Pull Request: https://projects.blender.org/blender/blender/pulls/154668
2026-02-25 17:07:49 +01:00
Brecht Van Lommel
84d4a2e9cf Refactor: Cycles: Split KernelImageTexture and KernelImageInfo
Make a distinction between an image texture for shading systems, and a
device image object. For full images this is the same, but for tiled
images we'll store the pixels across multiple device image objects.

Rename slot to image_info_id and image_texture_id to help distinguish
indexes into these.

Pull Request: https://projects.blender.org/blender/blender/pulls/154668
2026-02-25 17:07:39 +01:00
Brecht Van Lommel
527f9ea306 Refactor: Cycles: More consistent naming of image functions and structs
Previously there was a mix of "image" and "texture" to refer to the same
thing, use "image" when possible now. An exception is MEM_IMAGE_TEXTURE
to avoid conflicts with the MEM_IMAGE macro on Windows.

Pull Request: https://projects.blender.org/blender/blender/pulls/152665
2026-01-14 17:57:46 +01:00
Sergey Sharybin
cfc8cb55db Fix #152126: Cycles HIP: RDNA4 has rendering artifacts in volumes
The regression is caused by c0ad7c16dc.

Seems to be compiler issue. Hinting to unroll the loop solves the problem,
but introduces performance regression. So instead revert the code to the old
state for the HIP platform.

Additionally, move the weighting per-row weighting into the outter loop.
This requires an extra variable, but less multiplications.

Pull Request: https://projects.blender.org/blender/blender/pulls/152321
2026-01-06 11:48:49 +01:00
Weizhen Huang
992ad878fd Cycles: Improve compilation time of tricubic interpolation
by using a loop instead of unrolling all 64 evaluations.
Seems that two nested loops has the best performance.

Compilation time measured on Metal M2 Ultra:
|                              Kernel| Before|  After|
|                                  --|     --|     --|
|             integrator_shade_volume|148.13s|114.71s|
|integrator_shade_volume_ray_marching| 44.30s| 14.27s|
|             integrator_shade_shadow| 87.83s| 58.82s|
|          shader_eval_volume_density| 32.69s|  6.63s|

Also added test file because we were not testing deterministic tricubic
interpolation before

Ref: #150119
2025-11-28 14:43:35 +01:00
u3dreal
b597c0f1ed Fix: Cycles: IES interpolation artifacts at angular boundaries
Fixes artifacts in IES data interpolation where edge samples (e.g., v == 0 or
h_i == h_num-1) were clamped to 0.0f instead of valid intensity values.
2025-10-16 15:38:38 +02:00
Lukas Tönne
12f0bc7736 Fix #138388: Use grid voxel corners as value locations like OpenVDB
Blender grid rendering interprets voxel transforms in such a way that the voxel
values are located at the center of a voxel. This is inconsistent with OpenVDB
where the values are located at the lower corners for the purpose or sampling
and related algorithms.

While it is possible to offset grids when communicating with the OpenVDB
library, this is also error-prone and does not add any major advantage.
Every time a grid is passed to OpenVDB we currently have to take care to
transform by half a voxel to ensure correct sampling weights are used that match
the density displayed by the viewport rendering.

This patch changes volume grid generation, conversion, and rendering code so
that grid transforms match the corner-located values in OpenVDB.

- The volume primitive cube node aligns the grid transform with the location of
  the first value, which is now also the same as min/max bounds input of the
  node.
- Mesh<->Grid conversion does no longer require offsetting grid transform and
  mesh vertices respectively by 0.5 voxels.
- Texture space for viewport rendering is offset by half a voxel, so that it
  covers the same area as before and voxel centers remain at the same texture
  space locations.

Co-authored-by: Brecht Van Lommel <brecht@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/138449
2025-08-26 12:27:20 +02:00
Weizhen Huang
df496eb894 Cycles: use one-tap stochastic interpolation for volume
It has ~1.2x speed-up on CPU and ~1.5x speed-up on GPU (tested on Metal
M2 Ultra).

Individual samples are noisier, but equal time renders are mostly
better.

Note that volume emission renders differently than before.

Pull Request: https://projects.blender.org/blender/blender/pulls/144451
2025-08-14 15:22:44 +02:00
Weizhen Huang
ea45c776fd Cycles: introduce dual types
to replace some uses of dfdx/dfdy/differentials.
No functional change expected.

Pull Request: https://projects.blender.org/blender/blender/pulls/143178
2025-07-28 17:34:24 +02:00
Campbell Barton
9d41b04aec Cleanup: quiet warnings, typo 2025-07-18 12:03:53 +10:00
Brecht Van Lommel
646dc7fe4d Cycles: Use stochastic sampling to speed up tricubic volume filter
Stochastically turn a tricubic filter into a trilinear one. This
reduces the number of taps from 64 to 8. It combines ideas from
the "Stochastic Texture Filtering" paper and our previous GPU
sampling of 3D textures.

This is currently only used in a few places where we know stochastic
interpolation is valid or close enough in practice.
* Principled volume density, color and temperature
* Motion blur velocity

On an Macbook Pro M3 with the openvdb_smoke.blend regression test
and cubic sampling, this gives a ~2x speedup for CPU and ~4x speedup
for GPU. However it also increases noise, usually only a little. Equal
time renders for this scene show a clear reduction in noise for both
CPU and GPU.

Note we can probably get a bigger speedup with acceptable noise trade-off
using full stochastic sampling, but will investigate that separately.

Pull Request: https://projects.blender.org/blender/blender/pulls/132908
2025-07-09 21:04:38 +02:00
Brecht Van Lommel
4c25b49875 Refactor: Cycles: Deduplicate 3D texture sampling between devices
Pull Request: https://projects.blender.org/blender/blender/pulls/132908
2025-07-09 21:04:38 +02:00
Brecht Van Lommel
15390b9257 License: Change NanoVDB header to Apache 2, following upstream OpenVDB
This license was changed upstream, and it's simpler if we can use the same as
most of the Cycles code.
2025-03-27 14:48:06 +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
7db0bc2e64 Refactor: Cycles: Make math and type headers work by themselves
Remove separate impl.h headers, 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:47 +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
Brecht Van Lommel
d72c4f0096 Fix: Cycles build issues when disabling various kernel features 2024-06-13 19:41:19 +02:00
Brecht Van Lommel
d377ef2543 Clang Format: bump to version 17
Along with the 4.1 libraries upgrade, we are bumping the clang-format
version from 8-12 to 17. This affects quite a few files.

If not already the case, you may consider pointing your IDE to the
clang-format binary bundled with the Blender precompiled libraries.
2024-01-03 13:38:14 +01:00
Campbell Barton
dc2d7a4707 License headers: conform copyright to SPDX 2023-12-12 13:03:26 +11:00
Brecht Van Lommel
6cdb43195e Refactor: replace NanoVDB kernel side implementation by own code
The NanoVDB headers are not compatible with Metal due to missing address
space qualifiers. We currently have a big patch for NanoVDB header
files, which is difficult to update for OpenVDB 11. Instead extract a
few hundred lines of code from NanoVDB to do just what we need.

Pull Request: https://projects.blender.org/blender/blender/pulls/115992
2023-12-10 19:37:36 +01:00
Campbell Barton
e38ff7c06d Cleanup: use C++ comments for disabled code 2023-09-25 17:06:04 +10:00
Campbell Barton
2721b937fb Cleanup: use braces in headers 2023-09-24 14:52:38 +10:00
Campbell Barton
c12994612b License headers: use SPDX-FileCopyrightText in intern/cycles 2023-06-14 16:53:23 +10:00
Lukas Stockner
888bdc1419 Cycles: Remove MultiGGX code, replace with albedo scaling
While the multiscattering GGX code is cool and solves the darkening problem at higher roughnesses, it's also currently buggy, hard to maintain and often impractical to use due to the higher noise and render time.

In practice, though, having the exact correct directional distribution is not that important as long as the overall albedo is correct and we a) don't get the darkening effect and b) do get the saturation effect at higher roughnesses.

This can simply be achieved by adding a second lobe (https://blog.selfshadow.com/publications/s2017-shading-course/imageworks/s2017_pbs_imageworks_slides_v2.pdf) or scaling the single-scattering GGX lobe (https://blog.selfshadow.com/publications/turquin/ms_comp_final.pdf). Both approaches require the same precomputation and produce outputs of comparable quality, so I went for the simple albedo scaling since it's easier to implement and more efficient.

Overall, the results are pretty good: All scenarios that I tested (Glossy BSDF, Glass BSDF, Principled BSDF with metallic or transmissive = 1) pass the white furnace test (a material with pure-white color in front of a pure-white background should be indistinguishable from the background if it preserves energy), and the overall albedo for non-white materials matches that produced by the real multi-scattering code (with the expected saturation increase as the roughness increases).

In order to produce the precomputed tables, the PR also includes a utility that computes them. This is not built by default, since there's no reason for a user to run it (it only makes sense for documentation/reproducibility purposes and when making changes to the microfacet models).

Pull Request: https://projects.blender.org/blender/blender/pulls/107958
2023-06-05 02:20:57 +02:00
Brecht Van Lommel
e949d6da5b Cycles: simplify handling of ray differentials
* Store compact ray differentials in ShaderData and compute full differentials
  on demand. This reduces register pressure on the GPU.
* Remove BSDF differential code that was effectively doing nothing as the
  differential orientation was discarded when making it compact.

This gives a 1-5% speedup with RTX A6000 + OptiX in our benchmarks, with the
bigger speedups in simpler scenes.

Renders appear to be identical except for the Both displacement option that
does both displacement and bump.

Differential Revision: https://developer.blender.org/D15677
2022-08-15 13:48:02 +02:00
Andrii Symkin
d832d993c5 Cycles: add new Spectrum and PackedSpectrum types
These replace float3 and packed_float3 in various places in the kernel where a
spectral color representation will be used in the future. That representation
will require more than 3 channels and conversion to from/RGB. The kernel code
was refactored to remove the assumption that Spectrum and RGB colors are the
same thing.

There are no functional changes, Spectrum is still a float3 and the conversion
functions are no-ops.

Differential Revision: https://developer.blender.org/D15535
2022-08-09 16:49:34 +02:00
Brecht Van Lommel
f26aa186b2 Cleanup: remove __KERNEL_CPU__
This was tested in some places to check if code was being compiled for the
CPU, however this is only defined in the kernel. Checking __KERNEL_GPU__
always works.
2022-07-25 17:43:35 +02:00
Brecht Van Lommel
ff1883307f Cleanup: renaming and consistency for kernel data
* Rename "texture" to "data array". This has not used textures for a long time,
  there are just global memory arrays now. (On old CUDA GPUs there was a cache
  for textures but not global memory, so we used to put all data in textures.)
* For CUDA and HIP, put globals in KernelParams struct like other devices.
* Drop __ prefix for data array names, no possibility for naming conflict now that
  these are in a struct.
2022-06-20 12:30:48 +02:00
Sebastian Herholz
bd327e3bf3 Fix: Sky models can return negative values
When converting from XYZ to RGB it can happen, in some sky models, that the resulting RGB values are negative.
Atm, this is not considered and the returned values for the sky model can be negative.

This patch clamps the returned RGB values to be `= 0.f`

Reviewed By: brecht, sergey

Differential Revision: https://developer.blender.org/D14777
2022-04-28 18:14:06 +02:00
Brecht Van Lommel
029b0df81a Fix Cycles blackbody shader not taking into account OpenColorIO config
Keep the existing Rec.709 fit and convert to other colorspace if needed, it
seems accurate enough in practice, and keeps the same performance for the
default case.
2022-04-18 19:14:34 +02:00
Brecht Van Lommel
9cfc7967dd Cycles: use SPDX license headers
* Replace license text in headers with SPDX identifiers.
* Remove specific license info from outdated readme.txt, instead leave details
  to the source files.
* Add list of SPDX license identifiers used, and corresponding license texts.
* Update copyright dates while we're at it.

Ref D14069, T95597
2022-02-11 17:47:34 +01:00
William Leeson
7b1c5712f8 Cycles: Replace saturate with saturatef
saturate is depricated in favour of __saturatef this replaces saturate
with __saturatef on CUDA by createing a saturatef function which replaces
all instances of saturate and are hooked up to the correct function on all
platforms.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D13010
2021-10-27 14:05:46 +02:00
Brecht Van Lommel
fd25e883e2 Cycles: remove prefix from source code file names
Remove prefix of filenames that is the same as the folder name. This used
to help when #includes were using individual files, but now they are always
relative to the cycles root directory and so the prefixes are redundant.

For patches and branches, git merge and rebase should be able to detect the
renames and move over code to the right file.
2021-10-26 15:37:04 +02:00
Brecht Van Lommel
d7d40745fa Cycles: changes to source code folders structure
* Split render/ into scene/ and session/. The scene/ folder now contains the
  scene and its nodes. The session/ folder contains the render session and
  associated data structures like drivers and render buffers.
* Move top level kernel headers into new folders kernel/camera/, kernel/film/,
  kernel/light/, kernel/sample/, kernel/util/
* Move integrator related kernel headers into kernel/integrator/
* Move OSL shaders from kernel/shaders/ to kernel/osl/shaders/

For patches and branches, git merge and rebase should be able to detect the
renames and move over code to the right file.
2021-10-26 15:36:39 +02:00