Commit Graph

13926 Commits

Author SHA1 Message Date
Weizhen Huang
68de483bf3 Fix: Ray Portal BSDF changing sd->flag when closure is not allocated
when ray exceeds `max_bounce`, we do not allocate any closure at
intersection. However, Ray Portal BSDF still added `SD_BSDF` flag,
resulting in undefined behavior in
`integrate_surface_bsdf_bssrdf_bounce()`.
This part of code was similar to Transparent BSDF, however, Transparent
closure was still allocated in this case.
To fix the undefined behavior, add `SD_BSDF` flag only when the Ray
Portal closure was allocated.
2024-05-13 19:10:02 +02:00
nutti
0d34f59854 Cleanup: Mark method as static to fix pylint error
Pull Request: https://projects.blender.org/blender/blender/pulls/121688
2024-05-13 16:02:56 +02:00
Lukas Stockner
12bf5ff7d4 Cycles: Cleanup: Remove unused hash function
Also move the remaining one to util/hash.h.
2024-05-13 02:48:54 +02:00
Michael Jones
09ba1486f8 Cycles: Select Metal compute device by default on Apple Silicon machines
_No response_

Pull Request: https://projects.blender.org/blender/blender/pulls/121672
2024-05-11 09:32:55 +02:00
Michael Jones
5508b41a40 Cycles: MetalRT optimisations (scene_intersect_shadow + random_walk)
This PR contains optimisations and a general tidy-up of the MetalRT backend.

- Currently `scene_intersect` is used for both normal and (opaque) shadow rays, however the usage patterns are different enough to warrant specialisation. Shadow intersection tests (flagged with `PATH_RAY_SHADOW_OPAQUE`) only need a bool result, but need a larger "self" payload in order to exclude hits against target lights. By specialising we can minimise the payload size in each case (which is helps performance) and avoid some dynamic branching. This PR introduces a new `scene_intersect_shadow` function which is specialised in Metal, and currently redirects to `scene_intersect` in the other backends.

- Currently `scene_intersect_local` is implemented for worst-case payload requirements as demanded by `subsurface_disk` (where `max_hits` is 4). The random_walk case only demands 1 hit result which we can retrieve directly from the intersector object (rather than stashing it in the payload). By specialising, we significantly reduce the payload size for random_walk queries, which has a big impact on performance. Additionally, we only need to use a custom intersection function for the first ray test in a random walk (for self-primitive filtering), so this PR forces faster `opaque` intersection testing for all but the first random walk test.

- Currently `scene_intersect_volume` has a lot of redundant code to handle non-triangle primitives despite volumes only being enclosed by trimeshes. This PR removes this code.

Additionally, this PR tidies up the convoluted intersection function linking code, removes some redundant intersection handlers, and uses more consistent naming of intersection functions.

On a M3 MacBook Pro, these changes give 2-3% performance increase on typical scenes with opaque trimesh materials (e.g. barbershop, classroom junkshop), but can give over 15% performance increase for certain scenes using random walk SSS (e.g. monster).

Pull Request: https://projects.blender.org/blender/blender/pulls/121397
2024-05-10 16:38:02 +02:00
Jeroen Bakker
79dfe8d37f Vulkan: Enable device feature dynamic rendering
In the near future the legacy framebuffer/renderpass/pipeline drawing
will be replaced by dynamic rendering. Dynamic rendering provide a
flexible API to reuse pipelines between framebuffers if they share
the same image formats.

Dynamic rendering is provided by `VK_KHR_dynamic_rendering` extension
and is supported by all platforms we support (Intel since HD4000, NVIDIA
since 700, AMD since GCN2 and llvmpipe).

Functions provided by extensions are loaded in a struct inside
`VKDevice`.

Pull Request: https://projects.blender.org/blender/blender/pulls/121642
2024-05-10 10:22:58 +02:00
Attila Áfra
26c93c8359 Cycles: Enable OIDN 2.3 lazy device module loading
This enables the new lazy module loading behavior introduced in OIDN 2.3,
without breaking compatibility with older versions of OIDN (using separate
code paths).

Also, the detection of OIDN support for devices is now much cleaner, and
devices do not need to be matched by PCI address or device name anymore.

Pull Request: https://projects.blender.org/blender/blender/pulls/121362
2024-05-07 14:07:39 +02:00
Attila Áfra
2a0a6f18cc Cycles: Add OpenImageDenoise quality option
This adds a new "Quality" option for OIDN to switch between the existing
"High" and "Balanced" modes and the new "Fast" mode introduced in OIDN 2.3.

Pull Request: https://projects.blender.org/blender/blender/pulls/121374
2024-05-06 18:56:16 +02:00
valadaptive
3bcb88993d Fix #104395: Blurry Cycles render preview at 1:1 zoom
Change the preview size comparison threshold, so that we only use linear
interpolation for the render preview when zoomed out, and use nearest
neighbor interpolation at 1:1 zoom.

Pull Request: https://projects.blender.org/blender/blender/pulls/120325
2024-05-06 13:46:18 +02:00
Campbell Barton
98f319ce02 Cleanup: spelling in comments 2024-05-04 15:24:46 +10:00
Campbell Barton
4f5f0040c0 Cleanup: back-tick quote file extensions in code-comments 2024-05-04 15:06:46 +10:00
Campbell Barton
9918488bb1 Cleanup: use uppercase tags, following own style guide 2024-05-03 11:33:21 +10:00
Campbell Barton
5529a94f14 Cleanup: spelling in comments 2024-05-03 11:33:18 +10:00
Campbell Barton
c7de9b9f4a Reapply "GHOST/Wayland: improve the error message for protocol errors"
This reverts commit 2b85314f05.
2024-05-03 10:55:17 +10:00
Campbell Barton
91b1077f7a GHOST/Wayland: expose wl_display_get_protocol_error function 2024-05-03 10:55:17 +10:00
David Murmann
aa70c687e4 Fix: Ray Portal BSDF unconnected direction wrong for OSL
Pull Request: https://projects.blender.org/blender/blender/pulls/121348
2024-05-02 19:35:02 +02:00
Sergey Sharybin
1b0012d51c Refactor: Require C++ for users of BLI_simd.h
This is because sse2neon.h might be used to emulate SSE intrinsics
on ARM64 architecture, and it uses some preprocessor which is not
available for C language when using MSVC.

The old-style math file math_matrix.c uses this header, so needed
to become C++. Simple rename did not work since there is a new math
utility math_matrix.cc exists. Following some existing convention
the math_matrix.c is renamed to math_matrix_c.cc. Eventually all the
code should switch to use C++ style math, and the C style removed,
so it seems reasonable to not mix old and new style of API in the
same file.

There should be no functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/121335
2024-05-02 16:22:19 +02:00
Lukas Stockner
17f2cdd104 Cycles: Add thin film iridescence to Principled BSDF
This is an implementation of thin film iridescence in the Principled BSDF based on "A Practical Extension to Microfacet Theory for the Modeling of Varying Iridescence".

There are still several open topics that are left for future work:
- Currently, the thin film only affects dielectric Fresnel, not metallic. Properly specifying thin films on metals requires a proper conductive Fresnel term with complex IOR inputs, any attempt of trying to hack it into the F82 model we currently use for the Principled BSDF is fundamentally flawed. In the future, we'll add a node for proper conductive Fresnel, including thin films.
- The F0/F90 control is not very elegantly implemented right now. It fundamentally works, but enabling thin film while using a Specular Tint causes a jump in appearance since the models integrate it differently. Then again, thin film interference is a physical effect, so of course a non-physical tweak doesn't play nicely with it.
- The white point handling is currently quite crude. In short: The code computes XYZ values of the reflectance spectrum, but we'd need the XYZ values of the product of the reflectance spectrum and the neutral illuminant of the working color space. Currently, this is addressed by just dividing by the XYZ values of the illuminant, but it would be better to do a proper chromatic adaptation transform or to use the proper reference curves for the working space instead of the XYZ curves from the paper.

Pull Request: https://projects.blender.org/blender/blender/pulls/118477
2024-05-02 14:28:44 +02:00
Jacques Lucke
2b85314f05 Revert "GHOST/Wayland: improve the error message for protocol errors"
This reverts commit a63e44a61f.

This lead to build failures on linux because `wl_display_get_protocol_error`
is not defined. The error happened on the buildbot too.
2024-05-02 10:23:42 +02:00
Campbell Barton
0f2827ff77 GHOST/Wayland: postpone mapping LIBDECOR windows
While there should be no user visible changes.
Follow LIBDECOR sample code by setting the app-id & title before
mapping the window.
2024-05-02 10:43:55 +10:00
Campbell Barton
a63e44a61f GHOST/Wayland: improve the error message for protocol errors
Include the interface that fails in a protocol error.
2024-05-02 10:28:35 +10:00
Campbell Barton
f735e4e611 GHOST/Wayland: prevent eternal loop in case of an error creating windows
Check & print a message if there is an error creating the window.
In both cases Blender will fail to start, it's just better to exit
quickly with a message instead of hanging.
2024-05-02 10:28:35 +10:00
Campbell Barton
2d152db090 GHOST/Wayland: use XDG_CURRENT_DESKTOP to detect GNOME
This change was made previously [0] but reverted as it caused the
title-bar to disappear on Ubuntu (see #121241).
Check if the value is set to GNOME delimited by `:`.

Previously checking the interfaces was used which has the down-side
that any compositor that adds `gtk_shell*` support may hang on startup
because of bugs in Blender/LIBDECOR as happened with WAYFIRE,
see reply to #76428.

[0]: 3a5389d5ab
2024-05-02 10:22:39 +10:00
Campbell Barton
848f1d8792 Cleanup: assign display as a variable on window creation
Reduces noise accessing the same value multiple times.
2024-05-02 10:20:54 +10:00
Michael Jones
99f5433445 Cycles: Dormant fixes for adaptive feature compilation
This PR fixes the (currently unused) scene-based selective feature compilation macros. These feature based macros haven't been used for a few years, and enabling them currently results in compilation errors.

The only functional change in this PR is in geom/primitive.h where undef-ing `__HAIR__` had exposed an inconsistency in how pointcloud attributes were being fetched. Using the more general `primitive_surface_attribute_float4` (instead of `curve_attribute_float4`) fixed a compilation error that occurred when rendering pointcloud unit test scenes with adaptive compilation enabled.

Pull Request: https://projects.blender.org/blender/blender/pulls/121216
2024-04-30 12:56:22 +02:00
Campbell Barton
d06c34b2e5 Cleanup: note that XDG_* environment variables can't be relied on
This assumption caused #121241.

Also correct `endif` comment.
2024-04-30 15:02:29 +10:00
Campbell Barton
e8de8ee85a Fix hang on startup under Wayland with the WayFire compositor (#2)
Disable use of LIBDECOR on WAYFIRE as it causes Blender to hang
on window creation.

Detect WAYFIRE using the presence of the `zwf_shell_manager_v*`
interface, don't use LIBDECOR if this is found.

This is an alternative fix to [0] which also disabled LIBDECOR
but caused LIBDECOR not to be used in GNOME on some systems.

I'm not keen on this solution, but it seems alternatives are less
reliable. See code-comment for details.

[0]: 3a5389d5ab
2024-04-30 14:50:56 +10:00
Campbell Barton
3a2fafba73 Revert "Fix hang on startup under Wayland with the WayFire compositor"
This reverts commit 3a5389d5ab.

It seems XDG_CURRENT_DESKTOP isn't reliably set,
causing no titlebar on GNOME, see #121241.

The WAYFIRE workaround will need to be resolved another way.
2024-04-30 14:34:55 +10:00
Michael Jones
9b833fdeba Cycles: Use more accurate GPU counter timestamps for profiling in Metal
This PR replaces the existing CPU wall-clock based profiling mechanism with more precise GPU counter based timestamps. As before, it is enabled by setting the env var `CYCLES_METAL_PROFILING=1`. Original implementation by Morteza Mostajabodaveh.

Pull Request: https://projects.blender.org/blender/blender/pulls/121208
2024-04-29 15:25:32 +02:00
Brecht Van Lommel
4832abf108 Cleanup: Compiler warning when building without OSL 2024-04-29 15:22:21 +02:00
David Murmann
ee51f643b0 Cycles: Ray Portal BSDF
Transport rays that enter to another location in the scene, with
specified ray position and normal. This may be used to render portals
for visual effects, and other production rendering tricks.

This acts much like a Transparent BSDF. Render passes are passed
through, and this is affected by light path max transparent bounces.

Pull Request: https://projects.blender.org/blender/blender/pulls/114386
2024-04-29 12:37:51 +02:00
Alaska
f8c0050a25 Shaders: Add Roughness to Subsurface Scattering Node
Matching the Principled BSDF.

Pull Request: https://projects.blender.org/blender/blender/pulls/114499
2024-04-29 10:54:29 +02:00
Campbell Barton
3a5389d5ab Fix hang on startup under Wayland with the WayFire compositor
Use XDG_CURRENT_DESKTOP to check if GNOME is running.

Previously the existence of a `gtk_shell*` interface was used however
the WAYFIRE compositor provides this interface which made GHOST require
LIBDECOR.

Initializing LIBDECOR was hanging as the initial configuration was
never seen. From a quick check it doesn't seem like a bug in Blender's
LIBDECOR use, the issue may be in either LIBDECOR or WAYFIRE.
Whatever the case, LIBDECOR isn't needed so workaround the bug by
changing how GNOME is detected.
2024-04-29 12:32:22 +10:00
Campbell Barton
c0def6c93d Cleanup: spelling in comments 2024-04-27 11:58:02 +10:00
Brecht Van Lommel
b306b3bd32 Fix #121097: Cycles issue with sharp edges in mesh edit mode
The normal domain needs to be checked after converting the editmesh to
mesh.
2024-04-26 20:08:41 +02:00
Alaska
afa66fc628 Shader: Clamp invalid inputs of various BSDF nodes
Clamp some of the inputs of the Glossy BSDF, Glass BSDF, Sheen BSDF,
and Subsurface Scattering nodes to improve consistency between render
engines and to avoid unexpected results.

* Clamp roughness to 0..1
* Clamp subsurface radius to 0..inf
* Clamp colors to 0..inf

Pull Request: https://projects.blender.org/blender/blender/pulls/120390
2024-04-26 17:39:39 +02:00
Alaska
03cb588529 Refactor: Cycles: Replace fixed Tangent input with custom input
This replaces the fixed Tangent input in BsdfNode::compile
with a custom input.

This is done because very few nodes actually use the tangent input
and it would be better to have this slot available for other inputs
on different nodes in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/119042
2024-04-26 15:25:14 +02:00
Campbell Barton
c444f128d3 WM: add a capability flag for physical trackpad direction
Support detecting if the trackpad direction flag is propertly set
(currently unused).

Needed so Wayland compositors that don't support seat-version 9 or
newer (GNOME-46 & KDE5 for e.g) can have a working trackpad.

Eventually this option will be removed when the functionality is
widely supported.
2024-04-26 21:26:49 +10:00
Sergey Sharybin
b24c91e93e Fix #119791: Cycles: Transparent hair curves render slow with volumes
The slowdown was caused by the volume step calculation returning an
infinite value. This was caused by the calculation happening before
the object bounds are calculated via the code path which does some
early update for the displacement and hair transparency. The actual
value was never re-calculated after bounds are valid.

The solution is to only clear need-update after the final call of
the device_update_flags().

Pull Request: https://projects.blender.org/blender/blender/pulls/121042
2024-04-24 20:15:58 +02:00
Ben-7
0136289cb6 CMake: Windows: clang-cl fixes
Support for building blender with clang on windows on x64 was added
years ago but given there are no active users support has crumbled a
bit.

This PR brings the build system back into working order but upstream
patches in openVDB are still required for a successful build see PR
#120317 for details.

Blender when build with clang the classroom scenes rendered on the cpu
with cycles is seeing a 5% reduction in render time on both an
AMD 7700x and an Intel 14900k.
2024-04-24 15:59:47 +02:00
YimingWu
ab72da8b5c Fix #120763: Fix memory leak in itasc cache
`Cache::addChannel` would return early when new cache entry insertion
isn't success, but the newly created cache entry isn't deleted upon
return, this patch fixes this.

Pull Request: https://projects.blender.org/blender/blender/pulls/120766
2024-04-24 09:35:04 +02:00
Campbell Barton
d544082e1d Fix #120925: Smooth scrolling mouse wheel broken on Wayland
Accumulate scrolling for mouse wheels that create scroll values below
a single "click".

Regression in [0], caused by bumping the seat API.

[0]: 8d86fb43a4
2024-04-23 13:34:59 +10:00
Fermin
821b773d95 FIX #109121: VR: Render controllers only if they are active
When turning on VR mode, if no controllers are available,
a fallback model (a sphere) is rendered in the middle of the VR area.

This change uses the OpenXR API to check if the controllers are
available, sets new properties in `GHOST_XrPose` and `wmXrController`
that store if each controller is active or not, and uses
those properties to render the controllers in the VR view only
when they are active.

NOTE: in `wmXrController`, two state properties have been included,
but only `grip_active` is currently used. `aim_active` has been
included for consistency, but it could be removed.

Pull Request: https://projects.blender.org/blender/blender/pulls/119989
2024-04-21 03:28:35 +02:00
Campbell Barton
fd589fdca4 Cleanup: various non functional C++ changes 2024-04-20 13:46:14 +10:00
Campbell Barton
c6a9b11ef6 Cleanup: use const pointers 2024-04-20 12:41:23 +10:00
Hans Goudey
7f5dd29abd Subdiv: Make OpenSubdiv_TopologyRefiner into a C++ class
Replace the C-class pattern function pointers with actual class methods.
Other than the obvious benefit of not requiring the "this" pointer to be
explicitly passed into every function call, this will make it much simpler
to remove the entire C-API class and replace it with its "impl" next.

For that next step we need to expose code to the implementation
of the topology refiner, so instead of defining stubs locally in the
opensubdiv intern class, we spread some WITH_OPENSUBDIV checks
in the blenkernel. As far as I know this is the only way to remove the
intermediate C-API and call opensubdiv functions directly from there.
2024-04-19 09:03:48 -04:00
Hans Goudey
ec09931d55 Subdiv: Use nested namespaces and static for opensubdiv module
Declaring the `blender::opensubdiv` namespace on one line is just shorter.
`static` is preferred over anonymous namespaces since it's locally visible.
2024-04-19 09:03:23 -04:00
Campbell Barton
4e8b24f1d1 Cleanup: spelling in comments & punctuation 2024-04-19 15:57:06 +10:00
Weizhen Huang
8e5840359f Refactor: deduplicate assignment of background light group
by ensuring `KernelLight.lightgroup` is properly assigned in
`device_update_light()`. The value is later retrieved via
`lamp_lightgroup(kg, lamp)`.

`light_manager->device_update()` is called after
`background->device_update()`, so the background light group should
already been assigned when `device_update_lights()` is called.

Pull Request: https://projects.blender.org/blender/blender/pulls/120714
2024-04-17 18:49:03 +02:00
Weizhen Huang
a6330cad7f Refactor: wrap block of codes into a function 2024-04-17 18:49:00 +02:00