Commit Graph

15261 Commits

Author SHA1 Message Date
Brecht Van Lommel
cedd7edd29 Cleanup: Cycles: Use gtest header instead of Blender test header
To avoid conflicts with glog logging macros, and because there is just no
need to have this dependency.

Pull Request: https://projects.blender.org/blender/blender/pulls/143719
2025-07-31 19:46:54 +02:00
Campbell Barton
941582324c Cleanup: pass const arguments to sort, use C++ radian conversion 2025-07-31 16:18:13 +10:00
Campbell Barton
7c5ba9cb2c Cleanup: pass const arguments in GHOST/Wayland implementation 2025-07-31 03:45:42 +00:00
Felipe Choi
024291987c GHOST/Wayland: add basic touch-screen support
Generate mouse events from touch devices on Wayland.

The code tracks a single contact point and converts it to mouse moves,
LMB presses & releases. Multi-touch, pinch & swipe aren't yet supported.

Addresses #121449.

Ref !143416

Co-authored-by: Campbell Barton <campbell@blender.org>
2025-07-31 03:20:08 +00:00
Weizhen Huang
f8eae6b58a Fix: Cycles: Division by zero in Oren-Nayar shader
`Eavg` can still be 1 for very small roughness, causing division by zero
when computing `Ems`.
A roughness of 1e-5 gives an `Evg` of 0.999998, seems reasonable.

Pull Request: https://projects.blender.org/blender/blender/pulls/143637
2025-07-30 16:57:00 +02:00
Patrick Mours
6487395fa5 Cycles: Add linear curve shape
Add new "Linear 3D Curves" option in the Curves panel in the render
properties. This renders curves as linear segments rather than smooth
curves, for faster render time at the cost of accuracy.

On NVIDIA Blackwell GPUs, this can give a 6x speedup compared to smooth
curves, due to hardware acceleration. On NVIDIA Ada there is still
a 3x speedup, and CPU and other GPU backends will also render this
faster.

A difference with smooth curves is that these have end caps, as this
was simpler to implement and they are usually helpful anyway.

In the future this functionality will also be used to properly support
the CURVE_TYPE_POLY on the new curves object.

Pull Request: https://projects.blender.org/blender/blender/pulls/139735
2025-07-29 17:05:01 +02:00
Stefan Werner
c81e1d95c1 Cycles: Fixed typo in my last commit 2025-07-29 10:53:13 +02:00
Weizhen Huang
a7042ca30c Fix: warning template-id-cdtor on gcc 2025-07-29 10:41:17 +02:00
Stefan Werner
e7312b1ad5 Cycles: Explicitly setting SYCL device for Embree
This fixes issues when using Embree on mutliple GPUs.
A previous workaround used separate contexts, this one now
lets us keep a single context for all GPUs.

Pull Request: https://projects.blender.org/blender/blender/pulls/143089
2025-07-29 10:40:28 +02:00
Brecht Van Lommel
f03ac5ec4b Fix #142876: Cycles crash with OSL and interactive updates
Update use_shading, use_camera and the shading system pointers in the same
location, so that when the render is interrupted they are in a consistent state.

The added null pointer checks are not strictly needed, but just in case it
goes out of sync for another reason.

Pull Request: https://projects.blender.org/blender/blender/pulls/143467
2025-07-28 18:43:57 +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
Weizhen Huang
345d23bff8 Cleanup: Cycles: add more float3 util functions
and vectorize `wrap` and `safe_fmod`.
2025-07-28 17:34:21 +02:00
Weizhen Huang
48777385c2 Cleanup: Cycles: simplify computation of dPdx and dPdy
`sd->dPdu`, `sd->dPdv`, `sd->du` and `sd->dv` are computed from
`sd->dP` by constructing a local frame, so both results are the same, subject to some numerical differences.

This avoids constructing the local frame again, so might be faster.
2025-07-28 17:34:21 +02:00
Weizhen Huang
f9a65ebbea Cleanup: Cycles: Deduplication svm bump functions 2025-07-28 17:34:21 +02:00
Sergey Sharybin
07bf1bd87b OpenSubdiv: Switch away from GLSL on Apple
Use MTLPatchShaderSource to provide the patch basis shader source on
all Apple platforms. The immediate advantage of this change is ability
to use GPU subdivision on iOS. Another advantage is that it moves us
further away from frameworks which got deprecated by Apple and it might
save us some headache in the future.

Also tweak backend-specific defines to match definitions from OpenSubdiv.
The annoying difference is that OSD_PATCH_BASIS_METAL is defined by the
OpenSubdiv as 1 in the very beginning of the base code, which is not done
for the OSD_PATCH_BASIS_GLSL is not defined by the OpenSubdiv at all.

Ref #143445

---

TODO:
- [X] Check it works correctly on macOS
- [x] Check it works correctly on Linux

Pull Request: https://projects.blender.org/blender/blender/pulls/143462
2025-07-28 16:54:10 +02:00
Habib Gahbiche
445eceb02a Nodes: Remove "Use Nodes" in Shader Editor for World
Part of https://projects.blender.org/blender/blender/pulls/141278

Blend files compatibility:
If a World exists and "Use Nodes" is disabled, we add new nodes to the
existing node tree (or create one if it doesn't) that emulates the
behavior of a world without a node tree. This ensures backward and
forward compatibility.

Python API compatibility:
- `world.use_nodes` was removed from Python API => **Breaking change**
- `world.color` is still being used by Workbench, so it stays there,
although it has no effect anymore when using Cycles or EEVEE.

Python API changes:
Creating a World using `bpy.data.worlds.new()` now creates a World with
 an empty (embedded) node tree. This was necessary to enable Python
scripts to add nodes without having to create a node tree (which is
currently not possible, because World node trees are embedded).

Pull Request: https://projects.blender.org/blender/blender/pulls/142342
2025-07-28 14:06:08 +02:00
Brecht Van Lommel
fa007002b1 Refactor: Logging: Move G.quiet to CLOG, replace some printfs
* Replace G.quiet by CLG_quiet_set/get
* CLOG_INFO_NOCHECK prints are now suppressed when quiet, these were
  typically inside a if (!G.quiet) conditional already.
* Change some prints for blend files, color management and rendering to
  use CLOG, that were previously using if (!G.quiet) printf().

Pull Request: https://projects.blender.org/blender/blender/pulls/143138
2025-07-28 13:36:13 +02:00
Brecht Van Lommel
fbfa4e3805 Fix #143128: Cycles crash or artifacts with multi device rendering and denoising
Clear graphics interop when mapping the buffer directly, as this might free the
underlying buffer or handle.

Fix #141736: Artifacts on Vulkan GPU + GPU
Fix #143128: Crash on Metal CPU + GPU

Pull Request: https://projects.blender.org/blender/blender/pulls/143243
2025-07-25 21:43:01 +02:00
Sergey Sharybin
dcae48d1d3 Cycles: Add Portal Depth light pass information
It allows to implement tricks based on a knowledge whether the path
ever cam through a portal or not, and even something more advanced
based on the number of portals.

The main current objective is for strokes shading: stroke shader
uses Ray Portal BSDF to place ray to the center of the stroke and
point it in the direction of the surface it is generated for. This
gives stroke a single color which matches shading of the original
object. For this usecase to work the ray bounced from the original
surface should ignore the strokes, which is now possible by using
Portal Depth input and mixing with the Transparent BSDF. It also
helps to make shading look better when there are multiple stroke
layers.

A solution of using portal depth is chosen over a single flag due
to various factors:
- Last time we've looked into it it was a bit tricky to implement
	as a flag due to us running out of bits.
- It feels to be more flexible solution, even though it is a bit
	hard to come up with 100% compelling setup for it.
- It needs to be slightly different from the current "Is Foo"
	flags, and be more "Is Portal Descendant" or something.

An extra uint16 is added to the state to count the portal depth,
but it is only allocated for scenes that use Ray Portal BSDF.

Portal BSDF still increments Transparent bounce, as it is required
to have some "limiting" factor so that ray does not get infinitely
move to different place of the scene.

Ref #125213

Pull Request: https://projects.blender.org/blender/blender/pulls/143107
2025-07-25 18:09:38 +02:00
Michael Jones
6f1c63597d Cycles: Disable lossless MTLTexture compression & render up to 2% faster
Disallow lossless texture compression in MetalDevice. Path-tracing texture access patterns are very random, and cache reuse gains are typically too low to offset the decompression overheads. This change doesn't increase memory usage for any of the benchmark scenes (https://projects.blender.org/blender/blender-benchmarks/src/branch/main/cycles) as most textures are high entropy and don't compress well using lossless methods.

Pull Request: https://projects.blender.org/blender/blender/pulls/143074
2025-07-25 17:29:27 +02:00
Weizhen Huang
3a1fbe17b9 Fix: OSL: Attribute "generated" not available for World and Point Cloud
When "generated" is required via Attribute Node, it is not available for
World and Point Cloud.

Make OSL match the SVM behavior to use the object coordinates
(see `svm/attribute.h`),

Pull Request: https://projects.blender.org/blender/blender/pulls/143198
2025-07-25 15:39:06 +02:00
Brecht Van Lommel
47f9b7a98e Fix #142022: Cycles undisplaced normal not available
Previously with adaptive subdivision this happened to work with the N
attribute, but that was not meant to be undisplaced. This adds a new
undisplaced_N attribute specifically for this purpose.

For backwards compatibility in Blender 4.5, this also keeps N undisplaced.
But that will be changed in 5.0.

Pull Request: https://projects.blender.org/blender/blender/pulls/142090
2025-07-24 18:16:25 +02:00
Brecht Van Lommel
ba46217b51 Fix: GPU shader error logging doesn't show shader name or stage
This was relying on the souce file and line printing which is now disabled
by default. Also log the shader source without indent for readability.

Pull Request: https://projects.blender.org/blender/blender/pulls/142882
2025-07-24 16:10:19 +02:00
Brecht Van Lommel
264669fc03 Fix #142953: Cycles renders world lightgroup wrong
Pull Request: https://projects.blender.org/blender/blender/pulls/143003
2025-07-24 15:24:03 +02:00
Jonas Holzman
d95c2bc406 GHOST: Rename Metal Context from ContextCGL to ContextMTL
This commit renames the GHOST Metal graphic context class and related
files / references from `GHOST_ContextCGL` to `GHOST_ContextMTL`. When
the Metal backend was first introduced, this context file contained
both the old OpenGL context (CGL, for macOS Core OpenGL API), and the
newer Metal context. Since #110185 all CGL related code was removed
from the class, making it Metal only, and thus rendering the old class
name outdated and potentially misleading. In addition to the rename,
unused OpenGL related forward declarations and old TODOs were also
removed.

Pull Request: https://projects.blender.org/blender/blender/pulls/142519
2025-07-24 13:28:44 +02:00
Michael Jones
f3485cc925 Cycles: MetalRT: Only use extended limits if needed (revisited)
Currently MetalRT renders always use extended limits, which is needed to correctly render scenes where the max primitive count can exceed 2^28 or the instance count can exceed 2^24. This patch adopts Metal best practices of only enabling this flag if it is needed.

This PR is similar to #133364, but there are some notable differences:

1) The old PR made an overly optimistic assumption that all the relevant visibility bits could be squeezed into 8 bits. This new PR adopts the same approach that Optix takes of using 8 bits as a primary HW filter, and checking the full 32 bit mask inside the SW intersection handler.

~~2) I moved the scene scanning check from Scene into MetalDevice. This avoids platform specific details leaking into platform agnostic areas.~~

~~3) In live viewport mode, we always use extended limits in case we tip over the threshold.~~

_EDIT:_
2) The limits are scanned in `Scene::update_kernel_features`, and given to the device by a new `set_bvh_limits` method which returns true if the BVH and kernels need to be reloaded.

Pull Request: https://projects.blender.org/blender/blender/pulls/142401
2025-07-24 13:27:20 +02:00
Campbell Barton
c1b2a1af74 Cleanup: quiet unused warnings 2025-07-24 14:37:28 +10:00
Campbell Barton
c3b8702466 GHOST: ignore GHOST_ASSERT in release builds
Error in [0] made GHOST assert in release builds.

[0]: 4d227dd593
2025-07-24 01:10:25 +00: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
678ccd4a61 Cycles: Change default material to match Blender and EEVEE
Use Principled BSDF instead of Diffuse BSDF. This is a breaking change but
likely does not affect many scenes significantly. It adds some specularity
when an object does not have a a material assigned.

Fix #142538

Pull Request: https://projects.blender.org/blender/blender/pulls/142703
2025-07-22 15:54:30 +02:00
Brecht Van Lommel
474debc348 Refactor: Cycles: Make attribute map a bit smaller when not using OSL 2025-07-22 15:54:29 +02:00
Brecht Van Lommel
f861ad60e1 Fix #142603: Cycles slow updates in camera view with adaptive subdivision
Postpone update of adaptive subdivision until navigation is done, to keep
things a bit more interactive.

Pull Request: https://projects.blender.org/blender/blender/pulls/142730
2025-07-22 15:49:27 +02:00
Clément Foucault
32d64d35bb Refactor: GPU: Texture: Replace eGPUTextureFormat by TextureFormat
This offers better semantic and safety of the API.

Part of #130632

Pull Request: https://projects.blender.org/blender/blender/pulls/142818
2025-07-22 14:58:54 +02:00
Clément Foucault
f0254c2dcf Refactor: GPU: Remove unnecessary C wrappers for textures
This is the first step into merging `DRW_gpu_wrapper.hh` into
the GPU module.

This is very similar to #119825.

Pull Request: https://projects.blender.org/blender/blender/pulls/142732
2025-07-22 09:48:10 +02:00
Thomas Dinges
ce0ae95ed3 Cycles: Bump minimum supported CUDA architecture to sm_50
Pull Request: https://projects.blender.org/blender/blender/pulls/142212
2025-07-21 19:49:21 +02:00
Weizhen Huang
9404db8c7c Fix #141388: Cycles: CPU/GPU difference in pow function with 0 base
If the base is 0 and the exponent is non-zero, return 0 for both CPU and GPU.

Pull Request: https://projects.blender.org/blender/blender/pulls/142678
2025-07-21 14:45:30 +02:00
Weizhen Huang
5a27edcf79 Fix #141136: Cycles Hair black artifacts with direct coloring
fixed by clamping negative input colors

Pull Request: https://projects.blender.org/blender/blender/pulls/142667
2025-07-21 12:15:04 +02:00
Campbell Barton
008ed81d26 Fix #141777: Crash closing an unfocused window on Wayland 2025-07-20 16:31:57 +10:00
Campbell Barton
1762a66b82 Cleanup: use const cast 2025-07-20 15:27:07 +10:00
Jeroen Bakker
4de5da1ea2 OpenXR: Compile without OpenGL backend
This PR allows blender to be compiled with OpenXR, but without
OpenGL support.

For investigating a bug we needed to compile Blender without
OpenGL (`WITH_OPENGL_BACKEND=OFF`) but it would fail to
compile OpenXR (`WITH_XR_OPENXR=ON`). This PR tweakes
the preprocess directives to compile the openxr graphics
binding without OpenGL.

Co-authored-by: Jonas Holzman <jonas@holzman.fr>
Pull Request: https://projects.blender.org/blender/blender/pulls/141668
2025-07-19 21:40:49 +02:00
Sebastian Parborg
17b9759942 CMake: Sync up minimum version to 3.10
Besides being more consistent with the minimum version we use, this also
fixes warnings when using CMake 4.0.

Pull Request: https://projects.blender.org/blender/blender/pulls/142497
2025-07-19 20:37:10 +02:00
Nikita Sirgienko
9875836519 Cycles: oneAPI: Compile only needed device binaries in multi-GPU case
The code of the "oneapi_load_kernels" function before this modification
was loading kernels and compiling them, if needed, for all devices in
the associated GPU context. This makes sense for one GPU execution
scenario, as well as for execution scenario of multi identical GPU,
but in cases where Blender users have several different GPUs in
render, the previous implementation would compile all kernels
for all devices for each device, unnecessarily doing the same
work multiple times. Because of this, I am changing the
implementation so that now compilation happens only for the used
device per used device, ensuring that no unnecessary work is done.

No render performance changes are expected.
2025-07-19 14:15:36 +02:00
Sebastian Herholz
20e0fed7da Cycles: Fixing wrong PDF evaluation when BSDF closures are excluded by the light source
Pull Request: https://projects.blender.org/blender/blender/pulls/142323
2025-07-18 17:13:54 +02:00
Brecht Van Lommel
87ff645f5d Fix: Cycles preferences Python error after recent changes
Assigning properties in PropertyGroup has become more strict, define it in
__slots__ since it's a runtime property.

Pull Request: https://projects.blender.org/blender/blender/pulls/142357
2025-07-18 16:07:53 +02:00
Michael Jones
8077384e3a Cycles: Improve Metal kernel specialisation
This improves the existing scene specialisation mechanism by replacing "kernel_data.kernel_features" with a function constant. It doesn't cause any additional compilation requests, but allows the backend compiler to eliminate more dead code. An additional compiler hint is provided for dead-stripping "volume_stack_enter_exit" which results in slightly faster rendering of non-volumetric scenes.

Pull Request: https://projects.blender.org/blender/blender/pulls/142235
2025-07-18 11:18:43 +02:00
Campbell Barton
751cfe4a74 GHOST/Wayland: invert cursor color, pre-multiply alpha
- Cursors in wayland are expected to use pre-multiplied alpha.
  Note that cursor generators create straight alpha,
  pre multiplier in the wayland backend.
- Invert cursor colors on Wayland since dark cursors are often default,
  this could use dark theme settings in the future.
2025-07-18 14:13:38 +10:00
Campbell Barton
4e3b58423c Cleanup: use snake case for GHOST's can_invert_color argument 2025-07-18 12:53:32 +10:00
Campbell Barton
c52c8874e9 GHOST/Wayland: scalable vector cursor support via cursor-generators
Support showing vector cursors at the appropriate size based on each
monitors DPI.

This solves incorrectly sized cursors with Hi-DPI outputs as well as
supporting outputs with different DPI's.

Instead of passing pixel data, pass an object that can generate cursors,
GHOST/Wayland can then ensure the correct size is used based on the
display the cursor is shown on.

While may sound overly complicated it actually simplifies displaying
cursors on Wayland, especially for multiple monitors at different DPI's.
Showing cursors at higher or lower resolutions than the monitor's DPI
also behaves differently on GNOME & Plasma, resulting in situations
where the cursor would show larger/smaller than expected.

Details:

- Take advantage of the recently added SVG cursors & BLF time cursor
  !140990 & !141367.
- Setting bitmap cursors via GHOST_SetCustomCursorShape is now a no-op
  for Wayland since it's no longer used. This was supported in an
  earlier version of this PR and could be restored if needed.
- While fractional scaling works it relies on the compositor downscaling
  the cursors. Ideally they would be rendered at the target size but
  this isn't a priority as the difference isn't noticeable.

Ref !141597
2025-07-18 12:38:52 +10:00
Campbell Barton
9d41b04aec Cleanup: quiet warnings, typo 2025-07-18 12:03:53 +10:00
Brecht Van Lommel
df6d6c0932 Refactor: Cycles: Use logging system for GPU error print
Pull Request: https://projects.blender.org/blender/blender/pulls/142257
2025-07-17 21:14:30 +02:00