Commit Graph

797 Commits

Author SHA1 Message Date
Alexandre-Cardaillac
921c2b9d61 Shader: New Volume Coefficients Shader
Add a new shader node to control volume coefficients (scattering,
absorption and emission) directly, making it easier to model existing
volumes with measured data.

Pull Request: https://projects.blender.org/blender/blender/pulls/136287
2025-05-08 19:19:35 +02:00
Weizhen Huang
9cc252088e Fix: Cycles: mix weight not applied on volume emission with SVM
Pull Request: https://projects.blender.org/blender/blender/pulls/138081
2025-04-28 12:29:38 +02:00
Sergey Sharybin
30b962b3d8 Cycles: Optimize 3d and 4d noise
The goal is to reduce the affect of the fmod() used in the noise code,
which was initially reported in the comment:

    https://projects.blender.org/blender/blender/pulls/119884#issuecomment-1258902

Basic idea is to benefit from SIMD vectorization on CPU.

Tested on Linux i9-11900K and macOS on M2 Ultra, in both cases performance
after this change is very close to what it could be with the fmod() commented
out (the call itself, `p = p + precision_correction`).

On macOS the penalty of fmod() was about 10%, on Linux it was closer to 30%
when built with GCC-13. With Linux builds from the buildbot it is more like 18%.

The optimization is only done for 3d and 4d noise. It might be possible to
gain some performance improvement for 1d and 2d cases, but the approach would
need to be different: we'd need to optimize scalar version fmodf(). Maybe
tricks with integer cast will be faster (since we are a bit optimistic in the
kernel and do not guarantee exact behavior in extreme cases such as NaN inputs).

Pull Request: https://projects.blender.org/blender/blender/pulls/137109
2025-04-09 13:40:10 +02:00
Alaska
2e829ca4cf Fix #136303: Normalize the normals on the Ambient Occlusion node
This commit simply normalizes the normals of the Ambient occlusion
node before computing the output to avoid odd behaviour with
unnormalized normals.

Pull Request: https://projects.blender.org/blender/blender/pulls/136315
2025-03-27 02:58:19 +01:00
Brecht Van Lommel
f987ef7b6e Shaders: Add Filter Width input to Bump node
This makes it possible to restore previous Blender 4.3 behavior of bump
mapping, where the large filter width was sometimes (ab)used to get a bevel
like effect on stepwise textures.

For bump from the displacement socket, filter width remains fixed at 0.1.

Ref #133991, #135841

Pull Request: https://projects.blender.org/blender/blender/pulls/136465
2025-03-25 16:29:13 +01:00
Brecht Van Lommel
e813e46327 Cycles: Refactor lights to be objects
This is an intermediate steps towards making lights actual geometry.
Light is now a subclass of Geometry, which simplifies some code.

The geometry is not added to the BVH yet, which would be the next
step and improve light intersection performance with many lights.

This makes object attributes work on lights.

Co-authored-by: Lukas Stockner <lukas@lukasstockner.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/134846
2025-02-24 23:44:14 +01:00
Lukas Stockner
8cb5e05c48 Cleanup: Cycles: Deduplicate kernel attribute code using templating
The attribute handling code in the kernel is currently highly duplicated since
it needs to handle five different data types and we couldn't use templates
back then.
We can now, so might as well make use of it and get rid of ~1000 lines.

There are also some small fixes for the GPU OSL code:
- Wrong derivative for .w component when converting float2/float3->float4
- Different conversion for float2->float (CPU averages, GPU used to take .x)
- Removed useless code for converting to float2, not used by OSL

Pull Request: https://projects.blender.org/blender/blender/pulls/134694
2025-02-20 19:28:45 +01:00
Alaska
bcec81c4be Fix: Overflow when using light falloff node on distant lights
In Cycles lights can be given a light falloff node to control their
light falloff.

This worked by multiplying the light's strength by different
combinations of the ray length, which would be FLT_MAX for
distant lights. This resulting in almost every configuration of the
light falloff node overflowing when used on distant lights, which is
undesirable.

This commit fixes this issue by ignoring most of the functions of the
light falloff node when used on a distant light.

And in the process fixes a small discrepancy between SVM and OSL when
using the light falloff node on distant lights.

Pull Request: https://projects.blender.org/blender/blender/pulls/134539
2025-02-15 01:23:12 +01:00
Alaska
fee2f10208 Fix: Incorrect ray depth on emission in Cycles OSL
This commit fixes a issue where ray depth for emissive objects
(E.g. Lights) was incorrect when using the ray depth output of the
light path node in Cycles OSL.

Pull Request: https://projects.blender.org/blender/blender/pulls/134496
2025-02-14 05:09:08 +01:00
Weizhen Huang
b26221a06a Fix #74979: Cycles: Support Normal texture for bump mapping on triangles
The derivatives of the normal were simply not computed.

The offsetted normals are computed by perturbating the barycentric
coordinates. At triangle boundaries, the normals are extrapolated,
so discontinuities might be visible.

Currently only supported on triangles.

Pull Request: https://projects.blender.org/blender/blender/pulls/133769
2025-02-06 16:22:19 +01:00
Weizhen Huang
d2db9927ed Fix #86648: reduce ray differentials size for bump mapping
Use sub-pixel differentials for bump mapping helps with reducing
artifacts when objects are moving or when textures have high frequency
details.

Currently we scale it by 0.1 because it seems to work good in practice,
we can adjust the value in the future if it turns out to be impractical.

Ref: #122892

Pull Request: https://projects.blender.org/blender/blender/pulls/133991
2025-02-05 13:39:27 +01:00
Weizhen Huang
f4e4f19af2 Cleanup: Cycles: improve comments and variable names of bump-related functions
- Rename dx/dy -> dfdx/dfdy to match the actual computed quantity
- Add template functions to compute dfdx/dfdy on triangles for sharing
  among different data types
- Add documentation to some functions
- Some code shuffling that makes it easier to scale dfdx/dfdy in the
  future
- Some other trivial changes
2025-02-05 13:39:27 +01:00
Alex
c6d7bee181 Cycles: Burley diffuse closure for MaterialX compatibility
Add Burley diffuse to OSL for MaterialX compatibility. It is OSL only and
isn't a closure that will be looked for in SVM.

Pull Request: https://projects.blender.org/blender/blender/pulls/133845
2025-02-04 19:38:56 +01:00
Weizhen Huang
e9c39a6dcd Fix: Cycles: Wrong differentials of Wireframe nodes for bump mapping
Bump map differentials are computed in `svm_node_set_bump()`, other
shader nodes should just evaluate at shifted locations.

Pull Request: https://projects.blender.org/blender/blender/pulls/133876
2025-02-03 10:57:34 +01:00
Alaska
65ee136662 Fix: Cycles kernel build failure when building without subsurface scattering
In a recent refactor (1), the subsurface weight was set to be
constant, when it can be modified in the case that `__SUBSURFACE__`
is false, such as when using the adaptive compilation feature.

This commit fixes this issue by rearranging the code so the subsurface
weight is never overwritten.

(1) blender/blender@dd51c8660b

Pull Request: https://projects.blender.org/blender/blender/pulls/132620
2025-01-07 13:43:59 +01:00
Campbell Barton
d2d754be3f Cleanup: spelling in comments (make check_spelling*)
- Back-tick quote math expressions so differentiate them
  from English.
- Use doxygen code blocks for TEX expressions.
2025-01-04 16:26:39 +11: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
0a0696261d Cleanup: Cycles: clang-tidy warnings about missing switch default case
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:11 +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
Brecht Van Lommel
3c2a6fbb9c Refactor: Cycles: Use nullptr instead of NULL
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:22:43 +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
Thomas Dinges
22e16ca096 Cycles: add make_float4(float3 a, float b) type
This resolves a todo from the code. Part of the Quality Project.

Pull Request: https://projects.blender.org/blender/blender/pulls/131915
2024-12-17 09:11:08 +01:00
Weizhen Huang
c99b7e66b2 Cycles: support Mie Scattering with particle size smaller than 5um
Previous implemenation of 5 < d < 50 was taken from the main paper,
fitting for smaller sizes are found in the supplemental. They are less
forward-scattering.

Pull Request: https://projects.blender.org/blender/blender/pulls/130234
2024-12-13 15:50:54 +01:00
Weizhen Huang
16132f8c79 Fix #117667: Remove volume density weight cutoff
`CLOSURE_WEIGHT_CUTOFF` avoids allocating a closure when its weight is
too small. It makes sense for surface closures, but for volume closures
the contribution also depends on the object size/ray length, such a
cutoff seems random and is causing problem in atmospheric scatterings.

Therefore remove the cutoff for volume, just make sure the weight is
positive.

Pull Request: https://projects.blender.org/blender/blender/pulls/131696
2024-12-13 10:28:49 +01:00
Weizhen Huang
e2d7681fe6 Cleanup: Cycles: remove unused ccl_loop_no_unroll
Was added in 6121c28501 to ensure compiling
on OpenCL, now the definition is empty on all platforms

Pull Request: https://projects.blender.org/blender/blender/pulls/131100
2024-11-28 16:37:01 +01:00
Sergey Sharybin
51193ce71d Merge branch 'blender-v4.3-release' 2024-10-31 12:48:26 +01:00
Patrick Mours
3a36d638a5 Fix #127205: OptiX error with OSL material using wavelength node
The `osl_wavelength_color_vf` intrinsic was missing an implementation for
OptiX, causing a link error when attempting to load OSL shaders using the
wavelength node.

Pull Request: https://projects.blender.org/blender/blender/pulls/129372
2024-10-31 12:47:45 +01:00
Lukas Stockner
11ae08157e Revert Cycles SVM state cleanup due to Mac ARM test timeout
Not sure what is happening here, needs to be checked by someone on Mac.
Let's revert for now, it's not like this is a critical change.

Pull Request: https://projects.blender.org/blender/blender/pulls/110443
2024-10-08 00:33:56 +02:00
Lukas Stockner
0a4877264d Cycles: Cleanup: Move SVM execution state into a helper struct
This packs the SVM stack, current node offset and closure weight into one struct, and just passes that to each SVM node implementation.

This way we don't have to pass the offset back and forth all over the place, and adding additional state (e.g. for layering in the future) becomes easier.

Pull Request: https://projects.blender.org/blender/blender/pulls/110443
2024-10-07 19:09:52 +02:00
Lukas Stockner
b8d0bef3b4 Cleanup: Cycles: Consolidate coordinate system conversions
- Deduplicate Fisheye projection code
- Replace spherical/cartesian conversions with shared helpers
- Replace transforms from/to local coordinate systems with shared helpers

The main type of repeated transform that's not covered here is `to/from_coords`, but with separate values for xy and z (e.g. BSDFs that already computed `dot(wi, N)` earlier, so they only need `dot(wi, X)` and `dot(wi, Y)` later). Could also be replaced, but it would feel weirdly specific for a helper function.

Pull Request: https://projects.blender.org/blender/blender/pulls/125999
2024-10-07 02:18:49 +02:00
Alaska
0709743c0c Fix: Cycles: Rendering of the Principled BSDF when using adaptive kernel compilation
Fixes a issue where the Principled BSDF would render incorrectly if
`__SUBSURFACE__` is off. Which is common when using adaptive kernel
compilation (a unsupported Cycles feature).

Pull Request: https://projects.blender.org/blender/blender/pulls/128003
2024-10-04 12:39:03 +02: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
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
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
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
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
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
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
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
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
Campbell Barton
8fdb190278 Cleanup: typos in comments (duplicate words) 2024-07-14 18:55:43 +10:00
Campbell Barton
cd1dbab348 Cleanup: spelling in comments 2024-07-07 00:29:39 +10:00
Lukas Stockner
87159b2871 Cycles: Add Diffuse Roughness option to Principled BSDF
Setting this option to a value above zero replaces the lambertian Diffuse term
with the modified energy-preserving Oren-Nayar BSDF, which matches the OpenPBR
behavior.

Pull Request: https://projects.blender.org/blender/blender/pulls/123616
2024-07-01 15:49:09 +02:00
Weizhen Huang
e49fda3ff8 Merge branch 'blender-v4.2-release' 2024-06-25 18:50:54 +02:00