Commit Graph

13820 Commits

Author SHA1 Message Date
Xavier Hallade 891d71a4d4 Cycles: Drop noinline keyword for oneAPI device
fdc2962beb indirectly introduced a change
in inlining (light_tree_pdf started getting inlined) that led to a 5-10%
drop in performance for most scenes.
Dropping the noinline keyword for oneAPI device recovers it.
It however brings another performance regression to MNEE and Raytrace
kernels, that we'll look into separately.
2024-04-02 18:29:35 +02:00
Campbell Barton 97d93c7e33 GHOST/Wayland: pass in null when the cursor theme isn't set
While an empty string resolves to the default theme, it's not following
the API specification for wl_cursor_theme_load as it's written.

Checking on wayland internals this looks only to add an unnecessary
theme lookup on an empty string which falls back to the default.

Noticed when investigating #105895 although it seems unlikely
that this chagne would resolve the issue.
2024-04-02 15:11:05 +11:00
Campbell Barton 2be407fc82 Cleanup: spelling in comments 2024-04-01 16:47:57 +11:00
Hoshinova c78c6b0bdf Fix #119797: Noise Texture Precision Issues
The Perlin noise algorithms suffer from precision issues when a coordinate
is greater than about 250000.

To fix this the Perlin noise texture is repeated every 100000 on each axis.
This causes discontinuities every 100000, however at such scales this
usually shouldn't be noticeable.

Pull Request: https://projects.blender.org/blender/blender/pulls/119884
2024-03-29 16:12:23 +01:00
Brecht Van Lommel bd1f4343c3 Build: Improve OSL library dependency handling in Cycles
Might fix some missing symbols when the OSL library gets updated.

Pull Request: https://projects.blender.org/blender/blender/pulls/119391
2024-03-29 15:24:30 +01:00
Hans Goudey bf04da96f3 Fix: Missing change in declaration from previous commit 2024-03-28 19:01:32 -04:00
Hans Goudey 82b88f130a Cleanup: Use const for evaluated cage meshes and related data
Also access the evaluated deform mesh with a function rather than
directly from object runtime data. The goal is to make it easier to use
implicit sharing for these meshes and to improve overall const
correctness.
2024-03-28 18:57:57 -04:00
Campbell Barton 686605a6dd Cleanup: declare arrays as const where possible 2024-03-28 22:57:57 +11:00
Campbell Barton b2e00d1285 Cleanup: use const pointer arguments 2024-03-28 20:57:50 +11:00
Brecht Van Lommel 53e9fb6b78 Fix #117566: Cycles persistent data not updated by device preferences
Pull Request: https://projects.blender.org/blender/blender/pulls/119970
2024-03-27 18:55:46 +01:00
Brecht Van Lommel d2b38a475f Fix: Cycles Python error after previous commit 2024-03-27 18:04:19 +01:00
Alaska a0d5d9137b Fix #119937: Outdated tool tip for Automatic denoiser
Pull Request: https://projects.blender.org/blender/blender/pulls/119940
2024-03-27 17:49:58 +01: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
Campbell Barton 3f7742f65d GHOST/Wayland: only apply #119871 workaround with LIBDECOR
Disable fix from [0] unless LIBDECOR is used.

This caused:
- KDE 6.0.2 to fail to start full-screen.
- RIVERWM to show a blank preferences.
- HYPRLAND to assert with a negative window height
  when starting full-screen.

Also replace flush & dispatch with a round-trip which fixes an error
on GNOME with non maximized/full-screen windows not showing any contents
on startup until a redraw was triggered.

[0]: 7371b11bb5
2024-03-27 15:04:03 +11:00
Campbell Barton 40ab214c0a Cleanup: spelling in comments 2024-03-27 10:25:31 +11:00
Weizhen Huang c16fd219a8 Fix #70210: Cycles environment map sampling not accounting for negative values
Cycles samples environment map with a PDF proportional to the luminance.
This computation was assuming positive values, but generated texture
coordinates from world could have negative values, so the resulted CDF
was almost zero in the bug report scene.
Fixed by taking the absolute value when computing luminance in CDF.

Pull Request: https://projects.blender.org/blender/blender/pulls/119896
2024-03-26 16:24:36 +01:00
Weizhen Huang 1bf467aff6 Cleanup: make format 2024-03-26 09:39:22 +01:00
Alaska a4f1a52a5c Fix #119903: Cycles compilation on device that don't use the light tree
During the some of the shading for volumetrics, Cycles would try to
write to a variable that does not exist if the device has the
light tree disabled.

At the moment this only impacts AMD GPUs with the Metal backend.

Pull Request: https://projects.blender.org/blender/blender/pulls/119906
2024-03-26 08:20:09 +01:00
Hans Goudey fc0d8ba012 Cleanup: Remove C++ ifdef checks in C++ headers
Pull Request: https://projects.blender.org/blender/blender/pulls/119900
2024-03-26 04:56:03 +01:00
Weizhen Huang fdc2962beb Fix #114634: correlated samples in volume when using equiangular sampling and light tree
The same random number was used when sampling from the volume segment
and from the direct scattering position, causing correlation issues with
light tree.

To solve this problem, we ensure the same light is picked for
volume segment/direct scattering, equiangular/distance sampling by
sampling the light tree only once in volume segment. From the direct
scattering position in volume, we sample a position on the picked light
as usual. If sampling from the light tree fails, we continue with
indirect scattering.
For unbiased MIS weight for forward sampling, we retrieve the `P`, `D`
and `t` used in volume segment for traversing the light tree.

The main changes are:
1. `light_tree_sample()` and `light_distribution_sample()` now only pick
lights. Sampling a position on light is done separately via
`light_sample()`.
2. `light_tree_sample()` is now only called only once from volume
segment. For direct lighting we call `light_sample()`.
3. `light_tree_pdf()` now has a template `<in_volume_segment>`.
4. A new field `emitter_id` is added to struct `LightSample`, which just
stores the picked emitter index.
5. Additional field `previous_dt = ray->tmax - ray->tmin` is added to
`state->ray`, because we need this quantity for computing the pdf.
6. Distant/Background lights are also picked by light tree in volume
segment now, because we have no way to pick them afterwards. The direct
sample event for these lights will be handled by
`VOLUME_SAMPLE_DISTANCE`.
7. Original paper suggests to use the maximal importance, this results
in very poor sampling probability for distant and point lights therefore
excessive noise. We have a minimal importance for surface to balance, we
could do the same for volume but I do not want to spend much time on
this now. Just doing `min_importance = 0.0f` seems to do the job
okayish. This way we still won't sample the light with zero
`max_importance`.

The current solution might perform worse with distance sampling, because
the light tree measure is biased towards equiangular sampling. However,
it is difficult to perform MIS between equiangular and distance sampling
if different lights are picked for each method. This is something we can
look into in the future if proved to be a serious regression.

Pull Request: https://projects.blender.org/blender/blender/pulls/119389
2024-03-25 18:50:52 +01:00
Alaska 43cef92f66 Fix #119692: Cycles render issue with light tree and light linking
When using light linking with the light tree, the root index of a
mesh light subtree can be 0. The current code assumed this wasn't
possible, and as such it caused rendering issues, specifically the
incorrect computation of the PDF of certain mesh lights during
forward path tracing.

So we adjust the code to allow mesh light subtree root node
indices of 0.

This was worked on by Alaska, Sergey, and Weizhen

Pull Request: https://projects.blender.org/blender/blender/pulls/119770
2024-03-25 14:47:18 +01:00
Weizhen Huang 082b68fcb9 Cycles: improve equiangular sampling in volume
By restricting the sample range along the ray to the valid segment.

Supports

**Mesh Light**
- [x] restrict the ray segment to the side with MIS

**Area Light**
- [x] when the spread is zero, find the intersection of the ray and the bounding box/cylinder of the rectangle/ellipse area light beam
- [x] when the spread is non-zero, find the intersection of the ray and the minimal enclosing cone of the area light beam
*note the result is also unbiased when we just consider the cone from the sampled point in volume segment. Far away from the light source it's less noisy than the current solution, but near the light source it's much noisier. We have to restrict the sample region on the area light to the part that lits the ray then, I haven't tried yet to see if it would be less noisy.*

**Point Light**
- [x] the complete ray segment should be valid.

**Spot Light**
- [x] intersect the ray with the spot light cone
- [x] support non-zero radius

Pull Request: https://projects.blender.org/blender/blender/pulls/119438
2024-03-25 13:02:02 +01:00
Campbell Barton 7371b11bb5 Fix #119871: Window contents invalid on startup under Wayland & GNOME
Resolve a glitch where the window contents didn't fit the window
on startup under GNOME. This also avoids flickering whenever the
window manager changed the window size from the requested size.

See code-comments for details.
2024-03-25 22:08:27 +11:00
Sergey Sharybin bffcb000e8 Fix: Cycles crash on Metal GPU with ASAN builds
Running a very simple files when Blender is built with the
WITH_COMPILER_ASAN=ON and WITH_CYCLES_KERNEL_ASAN=ON CMake options
leads to ASAN reporting an unknown-crash at line where the worker
pool is being filled in.

It is not entirely clear if it is a real issue in the code, since
placing debug prints with `this` address report proper addresses,
however there is no harm on capturing `this` pointer by value and
it does solve the ASAN reporting issues.

It is possible to reproduce the ASAN crash with the following steps:
- Start with --factory-startup
- Enable Metal device in User Preferences
- Switch render device to GPU Compute
- Switch viewport more to Rendered

Pull Request: https://projects.blender.org/blender/blender/pulls/119867
2024-03-25 11:36:15 +01:00
Lukas Stockner 02a488d0fe Fix #61042: Cycles: Various Toon BSDF issues
The original bug report was that the Glossy Toon BSDF behaves incorrectly
when mixed with other closures.
The underlying issue here was that the eval function didn't check whether
the reflection angle is inside the valid cone and always returned its PDF,
which is very high compared to e.g. the diffuse closure's PDF for small
sizes (since the cone is supposed to be quite tight) and therefore breaks
MIS mixing.

However, while looking into this, I found a number of other issues, and so
this commit also contains several other changes to the Toon BSDFs:
- The angle that was used to compute the intensity wasn't the actual angle
  between the vectors. From what I can see, the formula that was used goes
  back all the way to the initial commit 12 years ago, so this probably was
  something that happened to work with one particular cone sampling method.
  Now, however, it caused weird asymmetric highlights, so replace it with
  the actual angle (which we already compute anyways).
- Setting size to zero caused the BSDF to go black, so clamp to 1e-5.
- The code was overall a bit repetitive, so I've cleaned it up a bit.
2024-03-24 23:52:16 +01:00
Lukas Stockner d4d5281d45 Fix: Cycles: Metal compilation error 2024-03-24 19:39:25 +01:00
Lukas Stockner 1f44be97e6 Fix #56355: Cycles: Wrong differentials for panoramic camera
The code to compute differentials mixed up the camera-space locations
of the raster coordinate and the camera itself, which caused the dP
differential to be set even when the ray origin is always the same.

This commit fixes that, reorganizes the code so that the Px/Py are
no longer used for both values to avoid future confusion, and skips
some unnecessary calculations stereo rendering isn't being used.
2024-03-24 17:52:22 +01:00
Hans Goudey 8b514bccd1 Cleanup: Move remaining GPU headers to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/119807
2024-03-23 01:24:18 +01:00
Campbell Barton 57dd9c21d3 Cleanup: spelling in comments 2024-03-21 10:02:53 +11:00
Weizhen Huang b81b0308fd Fix: `WITH_CYCLES_DEBUG` flag not enabled on Metal
seems to be enabled on other GPUs already

Pull Request: https://projects.blender.org/blender/blender/pulls/119701
2024-03-20 16:42:42 +01:00
Weizhen Huang a2bb547b9a Fix: Cycles spot light spread sampling not considering non-uniform scaling
For spherical spot light, when the shading point is close to the light
source, we switch to sampling the light spread instead of the visible
cone from the shading point. This has the benefit of less noise when the
spread is small.
However, the light spread sampling was not considering non-uniform
object scaling, where the actual spread might be different.
This patch switches sampling method only when the smallest enclosing
spread cone is smaller than the visible cone from the shading point.

An alternative method would be to compute the actual solid angle of the
scaled cone, and sample from the scaled cone. However, that involves
ray transformation and modifying the sampling pdf and angle. Since
non-uniform scaling is rather a niche case, it's probably not worth the
computation effort.

Pull Request: https://projects.blender.org/blender/blender/pulls/119661
2024-03-19 18:55:35 +01:00
Weizhen Huang a6fba7b59d Cleanup: Cycles: remove unnecessary storage of the spot light axes 2024-03-19 18:55:34 +01:00
Weizhen Huang 8536575263 Fix: Cycles area light ignores some valid samples in volume segment 2024-03-19 14:48:43 +01:00
Weizhen Huang f5f10201ca Cleanup: remove unused function 2024-03-19 14:48:14 +01:00
Brecht Van Lommel 433d91fca8 Merge branch 'blender-v4.1-release' 2024-03-18 11:00:49 +01:00
Brecht Van Lommel f57e4c5b98 Fix #119551: Cycles denoising crash canceling tiled render with MetalRT
The BVH has been freed at this point, but the Metal queue sets it on
every invocation. Make sure it's null so it doesn't get used anymore.

Pull Request: https://projects.blender.org/blender/blender/pulls/119581
2024-03-18 11:00:21 +01:00
Brecht Van Lommel b8ea467475 Merge branch 'blender-v4.1-release' 2024-03-16 19:45:51 +01:00
Alaska b8a3560a77 Fix #119545: Error drawing Cycles denoising settings with NONE device
Pull Request: https://projects.blender.org/blender/blender/pulls/119547
2024-03-16 19:34:16 +01:00
Weizhen Huang 8cbc386152 Fix: Cycles NEE not excluding self intersection
which resulted in bias when self intersection is excluded in forward scattering.
Below is a comparison using principled BSDF with emission. NEE and MIS were much brighter.

Pull Request: https://projects.blender.org/blender/blender/pulls/119440
2024-03-15 18:31:24 +01:00
Weizhen Huang 161881322e Merge branch 'blender-v4.1-release' 2024-03-15 18:13:40 +01:00
Weizhen Huang 682f984dbe Fix: Cycles mesh light ignores some valid samples in volume segment
Ref: #118534
turns out `in_volume_segment` does need to be checked. If the ray origin
lies on the wrong side of the mesh light, part of the ray could still be
lit by the other side, so the sample should not be considered invalid.

Pull Request: https://projects.blender.org/blender/blender/pulls/119529
2024-03-15 18:11:40 +01:00
Sergey Sharybin f3f79ef4bd Merge branch 'blender-v4.1-release' 2024-03-15 09:53:25 +01:00
Alaska 7ec0ebf30c Cycles: Fix grammar issues in OIDN GPU command line reporting
Pull Request: https://projects.blender.org/blender/blender/pulls/119492
2024-03-15 09:52:47 +01:00
Brecht Van Lommel 335ff6efab Cycles: Disable OpenImageDenoise support for AMD GPUs in Blender 4.1
In older drivers with an integrated GPU, this may crash. This not only
affects HIP, but also can crash when using Cycles with an NVIDIA or
Intel GPU in combination with an AMD CPU.

Fixes for this are expected to be coming, but there will not be enough
time for user testing, and it is difficult to be certain that the fix
is complete.

So to be careful, this is postponed until it has had more testing.

Pull Request: https://projects.blender.org/blender/blender/pulls/119476
2024-03-14 18:18:18 +01:00
Campbell Barton fc13d2c165 Cleanup: format 2024-03-12 20:56:48 +11:00
Jose Vicente Barrachina 692de6d380 GHOST/Wayland: copy & paste image to clipboard support
Adds copy and paste images functionality to and from the image editor
in Linux/Wayland clipboard.

Currently the only format supported is PNG.

Ref: !119117
2024-03-12 17:42:02 +11:00
Campbell Barton fff99c2e62 Merge branch 'blender-v4.1-release' 2024-03-12 17:08:53 +11:00
Campbell Barton dd42a9718d Cleanup: format 2024-03-12 17:08:29 +11:00
Campbell Barton 8c276cb073 Merge branch 'blender-v4.1-release' 2024-03-12 17:04:59 +11:00