Commit Graph

3621 Commits

Author SHA1 Message Date
Campbell Barton
4fa3dc0dd4 Cleanup: spelling in comments, use uppercase tags 2024-10-03 12:11:52 +10:00
Alexandre Cardaillac
0315eae536 Cycles: Add more scattering phase functions
Previously, Cycles only supported the Henyey-Greenstein phase function for volume scattering.
While HG is flexible and works for a wide range of effects, sometimes a more physically accurate
phase function may be needed for realism.

Therefore, this adds three new phase functions to the code:
Rayleigh: For particles with a size below the wavelength of light, mostly athmospheric scattering.
Fournier-Forand: For realistic underwater scattering.
Draine: Fairly specific on its own (mostly for interstellar dust), but useful for the next entry.
Mie: Approximates Mie scattering in water droplets using a mix of Draine and HG phase functions.

These phase functions can be combined using Mix nodes as usual.

Co-authored-by: Lukas Stockner <lukas@lukasstockner.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/123532
2024-10-02 11:12:53 +02:00
Nikita Sirgienko
fb21f3fb56 Cleanup: Cycles: oneAPI: Fix deprecation warnings about get_pointer() 2024-10-01 22:26:15 +02:00
Xavier Hallade
284b89a0a3 Cycles: oneAPI: compile kernels with fast-relaxed-math
This enables most of the GPU compiler's optimizations while -ffast-math
isn't set at DPC++ level.
It brings an overall 1% speedup and currently doesn't change the unit
tests pass rate.
2024-09-30 21:40:00 +02:00
Lukas Stockner
de80c24ed4 Cleanup: Cycles: Rename CYCLES_x_KERNEL_FLAGS to CYCLES_x_FLAGS in CMake
Pull Request: https://projects.blender.org/blender/blender/pulls/128342
2024-09-30 15:58:31 +02:00
Sahar A. Kashi
26ed4d3892 Cycles: Linux Support for HIP-RT
This change switches Cycles to an opensource HIP-RT library which
implements hardware ray-tracing. This library is now used on
both Windows and Linux. While there should be no noticeable changes
on Windows, on Linux this adds support for hardware ray-tracing on
AMD GPUs.

The majority of the change is typical platform code to add new
library to the dependency builder, and a change in the way how
ahead-of-time (AoT) kernels are compiled. There are changes in
Cycles itself, but they are rather straightforward: some APIs
changed in the opensource version of the library.

There are a couple of extra files which are needed for this to
work: hiprt02003_6.1_amd.hipfb and oro_compiled_kernels.hipfb.
There are some assumptions in the HIP-RT library about how they
are available. Currently they follow the same rule as AoT
kernels for oneAPI:
- On Windows they are next to blender.exe
- On Linux they are in the lib/ folder

Performance comparison on Ubuntu 22.04.5:
```
GPU: AMD Radeon PRO W7800
Driver: amdgpu-install_6.1.60103-1_all.deb
                       main         hip-rt
attic                  0.1414s      0.0932s
barbershop_interior    0.1563s      0.1258s
bistro                 0.2134s      0.1597s
bmw27                  0.0119s      0.0099s
classroom              0.1006s      0.0803s
fishy_cat              0.0248s      0.0178s
junkshop               0.0916s      0.0713s
koro                   0.0589s      0.0720s
monster                0.0435s      0.0385s
pabellon               0.0543s      0.0391s
sponza                 0.0223s      0.0180s
spring                 0.1026s      1.5145s
victor                 0.1901s      0.1239s
wdas_cloud             0.1153s      0.1125s
```

Co-authored-by: Brecht Van Lommel <brecht@blender.org>
Co-authored-by: Ray Molenkamp <github@lazydodo.com>
Co-authored-by: Sergey Sharybin <sergey@blender.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/121050
2024-09-24 14:35:24 +02:00
Campbell Barton
0fc27c8d81 Cleanup: spelling in comments 2024-09-20 13:14:57 +10:00
Alaska
27680118db Fix #127464: Disable HIPRT point clouds to fix performance regression
Temporarily disable point cloud rendering in HIPRT to fix a performance
regression triggered by increased register preasure until
a better solution can be developed.

Pull Request: https://projects.blender.org/blender/blender/pulls/127738
2024-09-17 17:59:18 +02:00
Nikita Sirgienko
d300098ee5 Fix #125093: Cycles: oneAPI: transparent shadows opaque when bounces>=1024
Pull Request: https://projects.blender.org/blender/blender/pulls/127404
2024-09-16 16:37:55 +02:00
Alaska
0e36107433 Fix: Cycles: Rendering of VDB files with HIP-RT
VDB files would fail to render in HIP-RT because NanoVDB wasn't
enabled when compiling HIP-RT kernels, resulting in NanoVDB textures
not being sampled and a blank result being returned instead.

The fix is to enable NanoVDB when compiling HIP-RT kernels.

Ref: #125086

Pull Request: https://projects.blender.org/blender/blender/pulls/127384
2024-09-12 16:26:41 +02:00
Weizhen Huang
ee2fe7fa6c Fix: Cycles: reuse random number for sampling color channel in volume
The same random number was used for sampling color channel at each step,
which leads to bias. Fixed by rescaling the random number.

Another possibility would be to scramble `rng_offset` and use a new
random number each time, similar as in subsurface scattering, but
rescaling random number should be faster than computing a new one, and
is favorable here since the precision here is not very important

Pull Request: https://projects.blender.org/blender/blender/pulls/127454
2024-09-12 14:27:56 +02:00
Xavier Hallade
33dd8dbdac Cycles: simplify fmodf(c, 1.0f) to fractf(c) in hsv node
Pull Request: https://projects.blender.org/blender/blender/pulls/127461
2024-09-12 11:53:07 +02:00
Xavier Hallade
473711b579 Build: avoid compiling Intel GPU binaries if no devices are set
Compilation command was malformed in this case.
2024-09-11 17:34:10 +02:00
Weizhen Huang
76700680d0 Cleanup: Cycles: rename variable for clarity
rename `rphase` to `rchannel` as this variable is only used for sampling
a color channel
2024-09-11 14:31:48 +02:00
salipourto
d4597e20b6 Fix #127131: Deforming motion blurred point clouds do not render in Cycles HIP-RT when BVH timesteps != 0
The device code was disabled for primitives with deformation blur
and the intersection function always returned false, hence no
rendered primitive.

Other than that, there were a few bugs on both device and host codes
(e.g., the order of current and previous times and the primitive name.)

Pull Request: https://projects.blender.org/blender/blender/pulls/127163
2024-09-06 12:27:17 +02:00
Nikita Sirgienko
94c9898f41 Fix #124811: Cycles: oneAPI: no hair strands in viewport with Embree
oneAPI kernels preloading logic was letting un-needed kernels to be
compiled without features, which would then miss when these kernels
were needed later.

Pull Request: https://projects.blender.org/blender/blender/pulls/127114
2024-09-04 11:08:00 +02:00
Alaska
8cf4d47fe2 Fix: Improve Cycles point clouds in HIPRT
Fixes a few issues with point clouds with HIPRT.
1. Crashing when building the BLAS due to an incorrect sized array.
2. A typo leading to all point cloud intersections being skipped.
3. A typo leading to some motion blurred point clouds rendering
as if they were stationary, or not rendering at all.

Pointclouds, with deformable motion blur, with BVH time steps set to >0
still do not render. Curves seem to have the same issue.

Ref #125086

Pull Request: https://projects.blender.org/blender/blender/pulls/125834
2024-09-03 16:31:41 +02:00
Weizhen Huang
77035192c9 Fix #126799: undefined behavior of shader node Arctan2 at (0, 0)
`atan2(0, 0)` is undefined on many platforms. To ensure consistent
result across platforms, we return `0` in this case.

Note only the behavior of the shader node `Artan2` is changed here.
During shading, we might still produce `atan2(0, 0)` internally and
cause different results across platforms, but that usually happens with
single samples and is not obvious, plus checking this condition all the
time is costly. If later we find out it's indeed necessary to change all
the invocation of `atan2(0, 0)`, we could change the wrapper functions
in `metal/compat.h` and `mtl_shader_defines.msl`.

Pull Request: https://projects.blender.org/blender/blender/pulls/126951
2024-09-03 11:44:59 +02:00
Xavier Hallade
1a0dbbd242 Fix: Cannot render Victor and Spring with embree disabled on Intel GPUs
The kernel zeroing memory since we've added host memory fallback didn't
expect large inputs, so with these scenes, it was running into
"Provided range is out of integer limits. Pass
`-fno-sycl-id-queries-fit-in-int' to disable range check" error.

This kernel was used instead of memset to avoid some issues with the
free_memory queries not always being updated.
As we can't reproduce these with recent drivers, we now use memset,
which fixes rendering with BVH2.
2024-09-02 18:35:51 +02:00
Campbell Barton
d497452a73 Cleanup: typo, spaces in comments, comment blocks & use double quotes 2024-08-29 17:16:44 +10:00
Alaska
84bab7f300 Fix #126592: Cycles light tree subtended angle not covering the entire bounding box
Use a bounding sphere instead of the corners of a bounding box to
compute the subtended angle of a light tree node.

Using the corners of the bounding box was an underestimate in some
scenes, causing some light tree nodes being incorrectly skipped.

Using the subtended angle of a bounding sphere is an overestimate, but
it covers the entire node and would not skip any valid contribution,
and no other reliable algorithm to compute the minimal enclosing angle
is known to us.

We expect some increase in noise due to overestimation, but this has
not been observed yet, in our benchmark scenes only a difference in
noise is visible.

Thanks to Weizhen for the suggestion to use the bounding sphere.

Pull Request: https://projects.blender.org/blender/blender/pulls/126625
2024-08-28 11:53:53 +02:00
Alaska
6ccb33e9fe Shader: Add Metallic BSDF Node
Add Metallic BSDF Node to the shader editor.

This node can primarily be used to create more realistic looking
metallic materials than the existing Glossy BSDF node.

This commit does not add any new closures to Cycles, it simply exposes
existing closures that were previous hard to access on their own.

- Exposes the F82 fresnel type that is currently used by the
metallic component of the Principled BSDF. Results should match
between the Metallic BSDF and Principled BSDF when using the same
settings.
- Exposes the Physical Conductor fresnel type that was previously
limited to custom OSL scripts. The Conductor fresnel type accepts
IOR and Extinction coefficients to define the appearance of the
material based off real life measurements.

EEVEE only supports the F82 fresnel type with internal code to convert
the the physical conductor inputs in to a colour format for F82,
which can lead to noticeable rendering differences with
some configurations.

Pull Request: https://projects.blender.org/blender/blender/pulls/114958
2024-08-27 17:20:46 +02:00
Weizhen Huang
be0d2e19b5 Fix #115998: Cycles volume too dark when shadow ray visibility is off
when tracing shadow ray through a volume and no hit is registered, we
consider the whole ray segment inside the volume.

However, no hit registered could also happen when the volume is
invisible to shadow ray. We should explicitly check this case and skip
rendering the volume segment instead.

Pull Request: https://projects.blender.org/blender/blender/pulls/126139
2024-08-19 15:52:35 +02:00
Sergey Sharybin
c5008d2de9 Fix #124679: Certain OSL scripts have artifacts in the world shader on Windows
Pull Request: https://projects.blender.org/blender/blender/pulls/126374
2024-08-16 10:35:32 +02:00
Campbell Barton
d71d325692 Cleanup: spelling in comments, strings 2024-08-16 09:33:20 +10:00
Omar Emara
075bdbcd63 Nodes: Improve isotropic Gabor noise UI controls
This patch improves the isotropic Gabor noise UI controls such that
variations happen in both directions of the base orientation, as opposed
to being biased in the positive direction only.

Thanks to Charlie Jolly for suggesting this improvement.
2024-08-14 15:26:03 +03:00
Omar Emara
ce89d7949c Nodes: Optimize Gabor noise variance estimation
This patch optimizes the Gabor noise standard deviation estimation by
computing the upper limit of the integral as the frequency approaches
infinity, since the integral is mostly constant for the relevant
frequency range. The limits are 0.25 for the 2D case and 1 / 4 * sqrt2
for the 3D case.

This also improves normalization for low frequencies, possibly due to
the effect of windowing.

Thanks to Charlie Jolly for spotting the optimization.
2024-08-14 14:27:23 +03:00
Omar Emara
847a3a7ea3 Nodes: Optimize Gabor noise with early exit
Optimize the Gabor noise texture code with an early exit for points that
are further away from the kernel center. This was already done for the
kernel, but is now being done earlier before computing the weight, so
its computation is now skipped.

Thanks to Charlie Jolly for the suggestion.
2024-08-14 12:12:34 +03:00
Alaska
a3b0c68ca9 Fix #123634: Missing 3D curve intersections with Metal BVH2
Fixes missing intersections on straight 3D curves with the
Metal backend, with BVH2.

This issue could of manifested on other devices, but didn't seem to
in practice.

Pull Request: https://projects.blender.org/blender/blender/pulls/126197
2024-08-13 16:49:28 +02:00
Sergey Sharybin
ce6454d02f Fix #126005: x64 Blender on Apple Silicon doesn't render properly in Cycles GPU
The GPU packed state is a static check from the Cycles core perspective,
and it is disabled for non-Apple Silicon GPUs. However, the Metal kernel
always used packed integrator.

This change makes it so the Host and Device side checks for the Host CPU
are aligned, and that Device-side packed state check does not differ from
the Host side.

Pull Request: https://projects.blender.org/blender/blender/pulls/126082
2024-08-08 16:01:23 +02:00
Lukas Stockner
90bcc3b5dc Fix #124646: Cycles: Point Density node still works on surfaces in OSL
This was already sort of disabled in 4.0 (in #109712), but still worked in OSL,
so let's make it consistent.

Pull Request: https://projects.blender.org/blender/blender/pulls/125928
2024-08-08 00:48:35 +02:00
Alaska
6b522c5e30 Fix #125307: Precision issues with MetalRT
Reverts a change in 5508b41a40 that
disabled ray offsetting on MetalRT, which lead to rendering artifacts
in scenes far away from the origin.

Pull Request: https://projects.blender.org/blender/blender/pulls/126003
2024-08-07 17:20:09 +02:00
David Murmann
df4df3cd52 Fix #114940: Cycles: GGX roughness has abrupt cutoff
This decreases BSDF_ROUGHNESS_SQ_THRESH so that the microfacet
roughness has a cutoff at much lower values and fixes a precision
issue in the bsdf_sample code that prevented this previously.

Pull Request: https://projects.blender.org/blender/blender/pulls/125919
2024-08-07 16:53:07 +02:00
Lukas Stockner
b119e1a497 Cycles: Fix potential NaN in normal mapping
I ran into this in a test scene - somehow the normalization here can result
in NaN (so presumably a zero vector). I don't think this has a notable
performance impact from some basic tests.

Pull Request: https://projects.blender.org/blender/blender/pulls/125930
2024-08-07 02:07:19 +02:00
Lukas Stockner
9ed7d38aac Cycles: Improve numerical precision of Beckmann distribution at low roughness 2024-08-06 23:04:16 +02:00
Weizhen Huang
d4ceade5ea Fix: Cycles BVH2 and Embree missing some transparent shadow bounces
the code snippet is supposed to compute the maximal `isect.t` in the
array, which is used to determine if subsequent intersections should be
added.

However, the previous implementation includes the old `isect.t` which is
going to be replaced, resulting an overestimation of `tmax_hits` and
thus missing closer intersections.

For BVH2, the issue is fixed by computing the `max_t` after a new entry
is inserted.

For Embree, the issue is fixed by finding the `second_largest_t` as well, and
compare that with the new insertion to find the new `max_t`.

Pull Request: https://projects.blender.org/blender/blender/pulls/125739
2024-08-06 15:37:49 +02:00
Weizhen Huang
e981389bdd Refactor: Cycles: use reservoir sampling to pick phase function in volume
so that we loop through the volumes only once.

Pull Request: https://projects.blender.org/blender/blender/pulls/125676
2024-08-05 10:55:47 +02:00
Weizhen Huang
7e40d567d4 Fix #125595: Cycles artifacts in overlapping volumes with different phase functions
A phase function is normalized over the sphere, it is therefore
incorrect to sum two phase functions together when evaluating for NEE.
It should be a weighted sum with normalized weights, which, according to
`volume_shader_phase_pick()`, is `sample_weight / sum_sample_weight`.

Also corrects an error in `volume_shader_phase_pick()`.
2024-08-05 10:55:44 +02:00
Campbell Barton
c071030ac3 Cleanup: spelling in comments 2024-08-04 13:45:06 +10:00
Alaska
5b61a01c19 Fix #125750: NaN on Glossy materials with low roughness
Fix a NaN when rendering glossy materials that can appear due to a
division by zero in bsdf_D when rendering materials with low roughness.

Thank you to Weizhen for the fix after my incorrect
first attempt.

Pull Request: https://projects.blender.org/blender/blender/pulls/125756
2024-08-02 16:28:42 +02:00
Alaska
5ce29bedf6 Fix: Cycles Shadow linking with HIP-RT
Fix shadow linking not working on HIP-RT by adding code to correctly
ignore certain shadow ray hits.

Ref #125086

Pull Request: https://projects.blender.org/blender/blender/pulls/125803
2024-08-02 12:17:09 +02:00
Alaska
ba5d76e7e2 Fix: Shader: Align vector math node reflect mode with OSL
Align Cycles SVM and EEVEE's rendering of the vector math node
in reflect mode with OSL when the normal vector is 0,0,0.

This is done by using safe_normalize rather than normalize on the
normal vector. Which also fixes a NaN in the reflect mode in this
specific configuration.

Pull Request: https://projects.blender.org/blender/blender/pulls/125688
2024-08-02 11:20:57 +02:00
Hans Goudey
edf298b505 Cleanup: Formatting 2024-07-29 23:10:49 -04:00
Campbell Barton
99af19932e Cleanup: spelling in comments 2024-07-30 12:38:16 +10:00
softyoda
5e9096829c Cycles: Add Central Cylindrical Panoramic camera model
This type of projection is often used e.g. in exhibitions that leverage big
curved screens.

Effectively, the frame is mapped onto a cylinder, with the x axis becoming the
longitude and y axis becoming the height.

Users can configure the min/max longitude, the min/max height and the radius of
the cylinder.

Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/123046
2024-07-29 15:03:57 +02:00
Alaska
8650068f0c Fix: NaN in vector math node in refract mode
Fix a NaN that can occur in the vector math node when set to
refract mode with a 'normal' input of length zero.

Pull Request: https://projects.blender.org/blender/blender/pulls/125374
2024-07-26 12:04:58 +02:00
Alaska
e7ce8d33e3 Fix #124642: OSL generates UVs for objects that don't have any
After e3697710d0, if no UV map was found, then Cycles OSL would
generate UV coordinates for users. This was done to add UV coordinates
to lights, however it had the side effect of creating new UV
coordinates for other object types that don't have a UV map.
This lead to a rendering difference between OSL and SVM
when rendering meshes with no UV map, and objects with no
UV map, like curves.

This commit fixes this issue by adding a new "is_light" attribute to
Cycles OSL and using that to figure out if UV coordinates should be
generated for lights.

Pull Request: https://projects.blender.org/blender/blender/pulls/124673
2024-07-24 12:16:44 +02:00
Campbell Barton
5794913fb8 Cleanup: CMake file indentation, wrap long lines 2024-07-22 09:58:45 +10:00
Jesse Yurkovich
138e914346 Fix #124745: Wrong stack offset for Voronoi lacunarity parameter
This would cause values plugged into the Smoothness socket to also be
used for Lacunarity.

Pull Request: https://projects.blender.org/blender/blender/pulls/124761
2024-07-16 18:58:25 +02:00
Sergey Sharybin
047568f633 Cycles: Add an assert for DeviceString construction
The motivation is to be able to catch issues like #124705 early on,
by relying on asserts.

The not-so-obvious part of the change is the change in the order of
includes, which is needed for the types.h to have definition of the
kernel_assert().

Pull Request: https://projects.blender.org/blender/blender/pulls/124729
2024-07-16 09:43:28 +02:00