Commit Graph

3727 Commits

Author SHA1 Message Date
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
Brecht Van Lommel
f80f97ca0d Refactor: Cycles: Rename rcp to reciprocal
To avoid symbol conflicts with upcoming HIP changes. Also remove
unused implementations for float4 and float8.

Pull Request: https://projects.blender.org/blender/blender/pulls/134045
2025-02-04 18:59:24 +01:00
Weizhen Huang
1b2ed045c1 Fix: Cycles: Wrong differentials of curve attributes
The barycentric coordinates u/v are aligned with the curve, but the
local coordinate system is created from the geometry normal and can
differ from uv.

Pull Request: https://projects.blender.org/blender/blender/pulls/133882
2025-02-03 10:58:25 +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
Lukas Stockner
0677e19fa0 Fix: Cycles: Wrong motion transform interpolation when using velocity
The issue here is that originally, the step count for the geometry's
motion and the object transform's motion were tied together, so a
single variable is used to store that step count.
However, when using the velocity attribute, it's possible for the step
counts to differ, which will lead to an incorrect interpolated object
transform in the kernel.

Pull Request: https://projects.blender.org/blender/blender/pulls/133788
2025-01-31 00:47:55 +01:00
Alex
0fdf916de2 Cycles: Sheen BSDF compatibility for MaterialX
Pull Request: https://projects.blender.org/blender/blender/pulls/133797
2025-01-30 11:15:43 +01:00
Alex
4c7129be72 Cycles: OSL subsurface_bssrdf compatibility for MaterialX
Pull Request: https://projects.blender.org/blender/blender/pulls/133612
2025-01-30 08:51:44 +01:00
Lukas Stockner
c997e61414 Cycles: Bump minimum OSL version to 1.13.4
That version has a bunch of API changes, so by dropping support for older
versions we can remove old compatibility code.
Also, that version is required for OptiX support, so building a fully-featured
Cycles wasn't possible with older OSL anyways.

Pull Request: https://projects.blender.org/blender/blender/pulls/133746
2025-01-29 21:17:21 +01:00
Campbell Barton
bd1ded952b Cleanup: spelling in comments 2025-01-29 12:31:19 +11:00
Lukas Stockner
a6e7bf2095 Cycles: Support Ray Depth attributes for OptiX OSL
Following the ShaderGlobals refactor, we can now easily pass IntegratorState
along on the GPU side as well, so let's implement these missing attributes.

Pull Request: https://projects.blender.org/blender/blender/pulls/133689
2025-01-29 01:01:08 +01:00
Lukas Stockner
e0d14d3b92 Cycles: Refactor: Store Cycles-specific pointers in our own ShaderGlobals
OSL has OSL::ShaderGlobals, which contains all the state for OSL shader
execution. The renderer fills it out and hands a pointer to OSL, and any
callbacks (e.g. for querying attributes) get the pointer back.

In order to store renderer-specific data in it, there's a few opaque pointers
in the struct, but using those has led to a mess of reinterpret_cast<> and
pointer indirection in order to carry all the data around.

However, there is a way to do this nicer: Good old C-style struct inheritance.
In short: Unless you're doing pointer arithmetic, you can just add additional
data at the end of a base struct, and the rest of the code won't care.

In this case, this means that we can have our own ShaderGlobals struct and
add more Cycles-specific data at the end. Additionally, we can replace the
generic opaque void pointers with ones of the correct type, which saves us
from needing to cast them back.

Since we have a copy of ShaderGlobals for GPU OSL anyways, it's just a matter
of refactoring the code a bit to make use of that.

The advantages of this are:
- Avoids casts all over the place, just needs one cast to turn our
  ShaderGlobals into the "base" type that OSL expects and one to turn the
  pointer that OSL gives us on callbacks back into our "derived" type.
- Removes indirection, all the relevant stuff (sd, kg, state) is now
  directly in the ShaderGlobals
- Removes some OSL-specific state from ShaderData, which helps to keep
  memory usage down

Pull Request: https://projects.blender.org/blender/blender/pulls/133689
2025-01-29 01:01:08 +01:00
Alex
e39b2ee816 Cycles: OSL oren_nayar_diffuse_bsdf compatibility for MaterialX
The oren_nayar_diffuse_bsdf closure in OSL had two issues:
- It broke when used with roughness of zero
- It only used the provided albedo for energy compensation, so it still
  required the user to multiply with the albedo

Therefore, this handles the zero roughness corner case and includes
the albedo in the closure weight.
This makes no difference when using the closure through the Diffuse
or Principled BSDF nodes, only for custom OSL shaders.

Pull Request: https://projects.blender.org/blender/blender/pulls/133597
2025-01-27 17:58:20 +01:00
Alex
4a4e456e37 Cycles: OSL uniform_edf closure for better MaterialX compatibility
Pull Request: https://projects.blender.org/blender/blender/pulls/133575
2025-01-25 21:17:17 +01:00
Brecht Van Lommel
82cc0a3eff Fix #124847: Cycles OSL UDIM wrong extrapolation with negative UV
Pull Request: https://projects.blender.org/blender/blender/pulls/133507
2025-01-23 22:20:52 +01:00
Brecht Van Lommel
e98b45beb1 Fix: Cycles CPU render wrong with latest OSL 1.14 2025-01-22 10:59:07 +01:00
Alaska
58b7543ede Fix #132322: Artifacts in Cycles volume rendering with Light tree on some devices
In a previous commit (1), adjustments to light tree traversal were made
to try and skip distant lights when deciding which light to sample
while within a world volume.

The skip wasn't implemented properly, and as a result distant lights
were still included in the light tree traversal in that sitaution.
And due to the way the skip was implemented, there were some
unintialized variables used in the processing of the distant lights
importance which caused artifacts on some platforms.

This commit fixes this issue by reverting the skip of distant lights
in that situation.

(1) blender/blender@6fbc958e89

Pull Request: https://projects.blender.org/blender/blender/pulls/132344
2025-01-22 05:50:32 +01:00
Weizhen Huang
e6645bf06b Fix #131240: Cycles: Negative integration range in Huang Hair
It is possible that the valid range computed from `theta` and the range
visible to the current pixel do not overlap. In this case the hair
section has no contribution.

Pull Request: https://projects.blender.org/blender/blender/pulls/133337
2025-01-21 11:48:45 +01:00
Alaska
b9ebd96539 Fix #133229: Remove camera size optimization from SSS shader in Cycles
In Cycles, the subsurface scattering shader will switch to a
diffuse shader under a few different conditions to improve performance
and reduce noise.

This commit removes the "switch back to diffuse if the scattering
radius is less than a quarter of a pixel" optimization because in some
scenes, this can result in noticable lines as the shader transitions
between subsurface scattering and diffuse.

Pull Request: https://projects.blender.org/blender/blender/pulls/133245
2025-01-21 04:31:43 +01:00
Weizhen Huang
350bd60b11 Fix: Cycles: Metal compilation when include is guarded behind WITH_CYCLES_DEBUG
Happens after f79cae2c59. Seems that Metal pre-processing could not
figure out that the inclusion is guarded behind `#ifdef`, so the
included file is expanded here and never again afterwards.
The pre-processing should be fixed, but for now just always include the file.

Pull Request: https://projects.blender.org/blender/blender/pulls/133336
2025-01-20 19:15:46 +01:00
Weizhen Huang
f79cae2c59 Fix: Cycles: Compilation issue with WITH_CYCLES_DEBUG enabled
Pull Request: https://projects.blender.org/blender/blender/pulls/133303
2025-01-20 16:11:38 +01:00
Stefan Werner
416085d893 Fix: Added missing include to allow Cylces build without Embree 2025-01-20 12:41:19 +01:00
Lukas Stockner
4f0aef1fde Fix #132516: Cycles: No NDC coordinates with OSL on OptiX
This attribute just wasn't implemented on OptiX. Not sure why, adding it works.
2025-01-20 03:42:02 +01:00
Brecht Van Lommel
f2bf9d747e Cleanup: Cycles: Remove some unused kernel entry points on CPU 2025-01-13 10:07:37 +01:00
Brecht Van Lommel
2bf6d0fd71 Cleanup: Cycles: Remove unnecessary SSE4.2 CPU kernel
This is the minimum requirement, so just the regular kernel already
includes these instructions if supported by the CPU architecture.
2025-01-13 10:07:37 +01:00
Alaska
4ca207a145 Cycles: Align Camera data output between SVM and OSL
The `ZDepth` output of the camera data node was different between SVM
and OSL.

SVM would output the `ZDepth`, with negative distances for points
behind the camera. While OSL would output the absolute of the distance,
which resulted in points behind the camera becoming positive.

Align OSL to SVM and allow outputting the negative distance as it
allows users to differentiate between what's in front or behind the
camera.

Pull Request: https://projects.blender.org/blender/blender/pulls/132837
2025-01-09 12:44:52 +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
5003253aca Cleanup: spelling & repeated terms 2025-01-07 13:20:19 +11:00
Brecht Van Lommel
faa17e2cc6 OpenShadingLanguage: Compatibility with version 1.14 (beta)
Pull Request: https://projects.blender.org/blender/blender/pulls/132654
2025-01-06 17:21:11 +01:00
Campbell Barton
77041084cd Cleanup: quiet uninitialised variable warnings in CMake 2025-01-06 17:57:11 +11: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
9971648783 Refactor: Cycles: Replace new/delete by unique_ptr, in simple cases
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:30 +01:00
Brecht Van Lommel
a8654a1dbe Refactor: Cycles: Make CPU kernel globals storage more sane
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:27 +01: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
f2c13cb639 Refactor: Cycles: Work around strange clang-tidy behavior in transform.h
Get rid of somewhat unusual include.

Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:17 +01:00
Brecht Van Lommel
689633d802 Refactor: Cycles: Avoid unsafe memcpy and memcmp
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:15 +01:00
Brecht Van Lommel
da5251f06c Cleanup: Cycles: Remove unused math_matrix.h
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:13 +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
d9150484a2 Cleanup: Cycles: Remove some unnecessary #if 0 and #if 1
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:09 +01:00
Brecht Van Lommel
71b8ecdd84 Cleanup: Cycles: Remove workaround for slow expf in glibc < 2.16
We're on 2.28 now, and were already on 2.17 for many years before that.

Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:03 +01:00
Brecht Van Lommel
3a57b97eba Cleanup: Cycles: Remove unneeded oneAPI double emulation for NanoVDB
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:22:59 +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
4951356ebc Refactor: Cycles: Stop using entire OIIO namespace
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:22:52 +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
f53e13411b Refactor: Cycles: Use #pragma once
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:22:45 +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
Campbell Barton
33e38c605f Cleanup: correct indentation for CMake files, strip trailing space 2025-01-03 13:23:38 +11:00