Commit Graph

83 Commits

Author SHA1 Message Date
Brecht Van Lommel
60bec183cb Refactor: Cycles: Replace foreach() by range based for loops
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
2025-01-03 10:23:05 +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
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
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
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
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
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
Omar Emara
4f51033708 Nodes: Implement Gabor noise
This patch implements a new Gabor noise node based on [1] but with the
improvements from [2] and the phasor formulation from [3].

We compare with the most popular existing implementation, that of OSL,
from the user's point of view:

  - This implementation produces C1 continuous noise as opposed to the
    non continuous OSL implementation, so it can be used for bump
    mapping and is generally smother. This is achieved by windowing the
    Gabor kernel using a Hann window.

  - The Bandwidth input of OSL was hard-coded to 1 and was replaced with
    a frequency input, which OSL hard codes to 2, since frequency is
    more natural to control. This is even more true now that that Gabor
    kernel is windowed as opposed to truncated, which means increasing
    the bandwidth will just turn the Gaussian component of the Gabor
    into a Hann window. While decreasing the bandwidth will eliminate
    the harmonic from the Gabor kernel, which is the point of Gabor
    noise.

  - OSL had three discrete modes of operation for orienting the kernel.
    Anisotropic, Isotropic, and a hybrid mode. While this implementation
    provides a continuous Anisotropy parameter which users are already
    familiar with from the Glossy BSDF node.

  - This implementation provides not just the Gabor noise value, but
    also its phase and intensity components. The Gabor noise value is
    basically sin(phase) * intensity, but the phase is arguably more
    useful since it does not suffer from the low contrast issues that
    Gabor suffers from. While the intensity is useful to hide the
    singularities in the phase.

  - This implementation converges faster that OSL's relative to the
    impulse count, so we fix the impulses count to 8 for simplicitly.

  - This implementation does not implement anisotropic filtering.

Future improvements to the node includes implementing surface noise and
filtering. As well as extending the spectral control of the noise,
either by providing specialized kernels as was done in #110802, or by
providing some more procedural control over the frequencies of the
Gabor.

References:

[1]: Lagae, Ares, et al. "Procedural noise using sparse Gabor
convolution." ACM Transactions on Graphics (TOG) 28.3 (2009): 1-10.

[2]: Tavernier, Vincent, et al. "Making gabor noise fast and
normalized." Eurographics 2019-40th Annual Conference of the European
Association for Computer Graphics. 2019.

[3]: Tricard, Thibault, et al. "Procedural phasor noise." ACM
Transactions on Graphics (TOG) 38.4 (2019): 1-13.

Pull Request: https://projects.blender.org/blender/blender/pulls/121820
2024-06-19 09:33:32 +02:00
Lukas Stockner
5e40b9bb5c Cycles: Switch to energy-preserving multiscattering Oren-Nayar BSDF
This multiscattering term comes from the OpenPBR specification and nicely
preserves energy while correctly modeling increased saturation at high
roughness.

Preparation for adding a diffuse roughness option to the Principled BSDF.

To me, the difference in output and computation seems small enough to
not need an enum for the old behavior.

Note that this also switches sampling to cosine-weighted, in my tests this
gives lower noise. I also checked doing MIS between cosine and uniform,
using the A term as a weight for how often to use cosine (since that term
is Lambertian diffuse), but always using cosine was better.
A nice consequence of that is that you don't get a huge noise jump when
going from 0.0 to 0.01 roughness.

Pull Request: https://projects.blender.org/blender/blender/pulls/123345
2024-06-18 21:07:21 +02:00
David Murmann
4cfae88f09 Fix #122739: mix causes unnecessary evaluation when ints are used
Fixes #122739.

I added all five missing conversions that the convert node can do in the svm code to the constant folding.

Pull Request: https://projects.blender.org/blender/blender/pulls/123035
2024-06-12 10:37:39 +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
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
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
Weizhen Huang
858349d821 Fix #113728: fireflies in Principled Hair Huang with MIS
The function `has_surface_transparent()` needs to be implemented in
order for hair with elliptical cross-sections to work correctly with MIS.

Pull Request: https://projects.blender.org/blender/blender/pulls/116088
2023-12-12 13:30:53 +01:00
Brecht Van Lommel
a1804f35f7 Shaders: change default IOR from 1.45 to 1.5
To match OpenPBR and Standard Surface. Most IOR real values are in a range
of 1.3 to 1.6, might as well use the more round and common number.

Pull Request: https://projects.blender.org/blender/blender/pulls/115770
2023-12-04 21:12:29 +01:00
Hoshinova
0b11c591ec Nodes: Merge Musgrave node into Noise node
This path merges the Musgrave and Noise Texture nodes into a single
combined Noise Texture node. The reasoning is that both nodes
intrinsically do the same thing, which is the layering of Perlin noise
derivatives to produce fractal noise. So the patch de-duplicates code
and unifies the use of fractal noise for the end use.

Since the Noise node had a Distortion input and a Color output, while
the Musgrave node did not, those are now available to the Musgrave types
as new functionalities.

The Dimension input of the Musgrave node is analogous to the Roughness
input of the Noise node, so both inputs were unified to follow the same
behavior of the Roughness input, which is arguable more intuitive to
control. Similarly, the Detail input was slightly different across both
nodes, since the Noise node evaluated one extra layer of noise. This was
also unified to follow the behavior of the Noise node.

The patch, coincidentally fixes an unreported bug causing repeated
output for certain noise types and another floating precision bug
#112180.

The versioning code implemented with this patch ensures backward
compatibility for both the Musgrave and Noise Texture nodes. When
opening older Blender files in Blender 4.1 the output of both nodes are
guaranteed to always be exactly identical to that of Blender files
created before the nodes were merged in all cases.

Forward compatibility with Blender 4.0 is implemented by #114236.
Forward compatibility with Blender 3.6 LTS is implemented by #115015.

Pull Request: #111187
2023-11-18 09:40:44 +01:00
Brecht Van Lommel
15d316a51a Fix #113777: Cycles IES texture not working for sphere lights
This was a regression after the sphere light changes, where the normal
now is the normal along the geometry of the light and no longer suitable
for the IES texture direction.

This not only fixes point lights with non-zero radius, but makes the IES
texture direction work consistently across light types and meshes,
always rotated by the object transform.
2023-10-18 20:40:07 +02:00
Alaska
85c4df2c42 Cycles: Update Glass BSDF to generalized_schlick
Update the Glass BSDF to internally use Generalized Schlick fresnel.
This allows for easier expansion of certain features in the future.

There should be no functional change from the users perspective.

Pull Request: https://projects.blender.org/blender/blender/pulls/112701
2023-10-09 19:17:15 +02:00
Lukas Stockner
b1a91c99bc Fix #111588: Cycles: Vector displacement with adaptive subdiv breaks normal
The compact form of the differential is not enough here, we need to store
and use the full vectors for bump evaluation.

Pull Request: https://projects.blender.org/blender/blender/pulls/112987
2023-10-02 02:19:51 +02:00
Brecht Van Lommel
3d38b51435 Shaders: add "Weight" to Transmission/Subsurface/Coat/Sheen socket names
Ref #99447
Ref #112848
2023-09-25 19:51:27 +02:00
Brecht Van Lommel
1d265eed5d Shaders: rename Specular to Specular IOR Level in Principled BSDF
To clarify that this is no longer the primary control, but rather
and adjustment on IOR.

Ref #99447
Ref #112552
2023-09-25 19:51:22 +02:00
Brecht Van Lommel
3e3bdc9b89 Shader: rename subsurface scattering methods and change default
Clarify that one was specifically designed for skin shading.

Ref #99447
Ref #112848
2023-09-25 19:50:50 +02:00
Brecht Van Lommel
334027063e Shader: use single Principled BSDF input for metallic and specular tint
To match Standard Surface and OpenPBR.

Ref #99447
Ref #112848
2023-09-25 19:50:44 +02:00
Brecht Van Lommel
ca5f1c0f00 Shaders: rename Principled BSDF Emission to Emission Color
Ref #99447
Ref #112848
2023-09-25 19:50:41 +02:00
Weizhen Huang
def9b76207 Shader: Change specular tint in Principled BSDF from float to color
For more artistic control. Tints the reflection of dielectric materials
at normal incidence.

Ref #99447

Pull Request: https://projects.blender.org/blender/blender/pulls/112192
2023-09-25 19:42:05 +02:00
Lukas Stockner
86156566a7 Cycles: Add Metallic Tint to Principled BSDF using F82-Tint model
With the default value, this is backwards-compatible.

Ref #99447

Pull Request: https://projects.blender.org/blender/blender/pulls/112551
2023-09-25 19:42:05 +02:00
Campbell Barton
5b9740c913 Cleanup: use braces for sources in intern/
Omitted intern/itasc as some of these sources are from KDL:
https://www.orocos.org/kdl.html
2023-09-17 09:05:40 +10:00
Lukas Stockner
5939810b3c Cycles: Remove unused Normal input on Hair BSDF
This was causing a warning when using OSL, since the OSL implementation
didn't implement the input.
Since the socket isn't really implemented on the Blender side anyways,
just get rid of it.

Also, the SVM code uses the shading normal while OSL used the geometric normal.
2023-09-16 03:29:46 +02:00
Lukas Stockner
4c229070a9 Cycles: Rework Principled BSDF Emission
- Changes defaults from Emission Color 0.0, Emission Strength 1.0 to be the
  other way around (Color 1.0, Strength 0.0), suggested by @brecht
- Makes emission component occluded by sheen and coat
  (to simulate e.g. dust-covered light sources)
- Moves transparency into the Principled SVM/OSL node, to allow for future
  support for e.g. transparent shadows in thin sheet mode.

Note that there are optimization opportunities here (mostly skipping the
non-transparent components for transparent shadow evaluation, and skipping
the parts that don't affect emission for light evaluation), but I have a
separate point for those in the Principled V2 planning since there's some
other optimization topics as well.

Co-authored-by: Weizhen Huang <weizhen@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/111155
2023-09-13 03:05:27 +02:00
Lukas Stockner
d7aee5a580 Cycles: Tweak Principled BSDF Subsurface parameters
Previously, the Principled BSDF used the Subsurface input to scale the radius.
When it was zero, it used a diffuse closure, otherwise a subsurface closure.
This sort of scaling input makes sense, but it should be specified in distance
units, rather than a 0..1 factor, so this commit changes the unit and renames
the input to Subsurface Scale.

Additionally, it adds support for mixing diffuse and subsurface components.
This is part of e.g. the OpenPBR spec, and the logic behind it is to support
modeling e.g. dirt or paint on top of skin. Before, materials would be either
fully diffuse (radius=0) or fully subsurface.

For typical materials, this mixing factor will be either zero or one
(just like metallic or transmission), but supporting fractional inputs makes
sense for e.g. smooth transitions at boundaries.

Another change is that there is no separate Subsurface Color anymore - before,
this was mixed with the Base Color using the Subsurface input as the factor,
but this was not really useful since that input was generally very small.

And finally, the handling of how the path enters the material for random walk
subsurface scattering is changed. Before, this always used lambertian (diffuse)
transmission, but this caused some problems, like overly white edges.

Instead, two different methods are now used, depending on the selected mode.
In Fixed Radius mode, the code assumes a simple medium boundary, and performs
refraction into the material using the main Roughness and IOR inputs.

Meanwhile, when not using Fixed Radius, the code assumes a more complex
boundary (as typically found on organic materials, e.g. skin), so the entry
bounce has a 50/50 chance of being either diffuse transmission or refraction
using the separate Subsurface IOR input and a fixed roughness of 1.
Credit for this method goes to Christophe Hery.

Pull Request: https://projects.blender.org/blender/blender/pulls/110989
2023-09-13 02:45:33 +02:00
Lukas Stockner
158dbc1b10 Cycles: Rework Principled BSDF Clearcoat
- Adds tint control, which simulates volumetric absorption inside the coating.
  This results in angle-dependent saturation and affects all underlying layers
  (diffuse, subsurface, metallic, transmission). It provides a physically-based
  alternative to ad-hoc effects such as tinted specular highlights.
- Renames the component from "Clearcoat" to "Coat", since it's no longer
  necessarily clear now. This matches naming in e.g. other renderers or OpenPBR.
- Adds an explicit Coat IOR input, in preparation for future smarter IOR logic
  around the interaction between Coat and main IOR. This used to be hardcoded
  to 1.5.
- Removes hardcoded 0.25 weight multiplier, and adds versioning code to update
  existing files accordingly. OBJ import/export still applies the factor.
- Replaces the GTR1 microfacet component with regular GGX. This removes a corner
  case in the Microfacet code, solves #53038, and makes us more consistent with
  other standard surface shaders. The original Disney BSDF used GTR1, but it
  doesn't appear that it caught on in the industry.

Co-authored-by: Weizhen Huang <weizhen@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/110993
2023-09-13 00:03:11 +02:00
Weizhen Huang
6f8011edf7 Cycles: new Principled Hair BSDF variant with elliptical cross-section support
Implements the paper [A Microfacet-based Hair Scattering
Model](https://onlinelibrary.wiley.com/doi/full/10.1111/cgf.14588) by
Weizhen Huang, Matthias B. Hullin and Johannes Hanika.

### Features:
- This is a far-field model, as opposed to the previous near-field
Principled Hair BSDF model. The hair is expected to be less noisy, but
lower roughness values takes longer to render due to numerical
integration along the hair width. The hair also appears to be flat when
viewed up-close.
- The longitudinal width of the scattering lobe differs along the
azimuth, providing a higher contrast compared to the evenly spread
scattering in the near-field Principled Hair BSDF model. For a more
detailed comparison, please refer to the original paper.
- Supports elliptical cross-sections, adding more realism as human hairs
are usually elliptical. The orientation of the cross-section is aligned
with the curve normal, which can be adjusted using geometry nodes.
Default is minimal twist. During sampling, light rays that hit outside
the hair width will continue propogating as if the material is
transparent.
- There is non-physical modulation factors for the first three
lobes (Reflection, Transmission, Secondary Reflection).

### Missing:
- A good default for cross-section orientation. There was an
attempt (9039f76928) to default the orientation to align with the curve
normal in the mathematical sense, but the stability (when animated) is
unclear and it would be a hassle to generalise to all curve types. After
the model is in main, we could experiment with the geometry nodes team
to see what works the best as a default.

Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/105600
2023-08-18 12:46:13 +02:00
Hoshinova
0702c24a36 Nodes: Add Lacunarity and Normalize inputs to Noise node
This PR adds the Lacunarity and Normalize inputs to the Noise node
similar to the Voronoi node.

The Lacunarity input controls the scale factor by which each
successive Perlin noise octave is scaled. Which was previously hard
coded to a factor of 2.

The Noise node normalizes its output to the [0, 1] range by default.
The Normalize option makes it possible for the user to disable that.
To keep the behavior consistent with past versions it is enabled by
default.

To make the aforementioned normalization control easer to implement,
the fractal noise code now accumulates signed noise and remaps the
final sum, as opposed to accumulating positive [0, 1] noise.

Pull Request: https://projects.blender.org/blender/blender/pulls/110839
2023-08-15 17:38:45 +02:00
Hoshinova
b880485492 Nodes: add Floored Modulo mode to Math nodes
Both the `Math` node and the `Vector Math` currently only explicitly
support modulo using truncated division which is oftentimes not the
type of modulo desired as it behaves differently for negative numbers
and positive numbers.

Floored Modulo can be created by either using the `Wrap` operation or
a combination of multiple `Math` nodes. However both methods obfuscate
the actual intend of the artist and the math operation that is actually
used.

This patch adds modulo using floored division to the scalar `Math` node,
explicitly stating the intended math operation and renames the already
existing `"Modulo"` operation to `"Truncated Modulo"` to avoid confusion.
Only the ui name is changed, so this should not break compatibility.

Pull Request: https://projects.blender.org/blender/blender/pulls/110728
2023-08-08 12:13:00 +02:00
Lukas Stockner
c66a694056 Cycles: Replace Sheen model in the Principled BSDF
This replaces the Sheen model used in the Principled BSDF with the
model from #108869 that is already used in the Sheen BSDF now.

The three notable differences are:
- At full intensity (Sheen = 1.0), the new model is significantly
  stronger than the old one. For existing files, the intensity is
  adjusted to keep the overall look similar.
- The Sheen Tint input is now a color input, instead of the
  previous blend factor between white and the base color.
- There is now a Sheen roughness control, which can be used to
  tweak the look between velvet-like and dust-like.

Pull Request: https://projects.blender.org/blender/blender/pulls/109949
2023-07-27 02:17:44 +02:00
Lukas Stockner
b220ec27d7 Cycles: Update Velvet BSDF to Sheen BSDF with new Microfiber sheen model
This patch extends the old Velvet BSDF node with a new shading model,
and renames it to Sheen BSDF accordingly.

The old model is still available, but new nodes now default to the
"Microfiber" model, which is an implementation of
https://tizianzeltner.com/projects/Zeltner2022Practical/.

Pull Request: https://projects.blender.org/blender/blender/pulls/108869
2023-07-24 15:36:36 +02:00
Lukas Stockner
89218b66c2 Cycles: Remove Transmission Roughness from Principled BSDF
This was already unsupported in combination with Multiscattering GGX,
prevented the Principled BSDF from using microfaced-based Fresnel for
Glass materials, and would have made future improvements even trickier.

Pull Request: https://projects.blender.org/blender/blender/pulls/109950
2023-07-22 04:16:49 +02:00
Weizhen Huang
0b3efc9d8c Cleanup: Cycles: remove SHARP distribution internally
this option was already unselectable in the UI, and is treated as GGX
with zero roughness. Upon building the shader graph, we only convert a
closure to `SHARP` when option Filter Glossy is not used and the
roughness is below certain threshold. The benefit is that we can avoid
calling `bsdf_eval()` or return earlier in some cases, but the thresholds
vary across files.
This patch removes `SHARP` closures altogether, and checks if the
roughness value is below a global threshold `BSDF_ROUGHNESS_THRESH`
after blurring, in which case the flag `SD_BSDF_HAS_EVAL` is not set.
The global threshold is set to be `5e-7f` because threshold smaller than
that seems to have caused problem in the past (c6aa0217ac). Also removes
a bunch of functions, variables and arguments that were only there
because we converted closures under certain conditions.

Pull Request: https://projects.blender.org/blender/blender/pulls/109902
2023-07-12 12:36:31 +02:00
Campbell Barton
c12994612b License headers: use SPDX-FileCopyrightText in intern/cycles 2023-06-14 16:53:23 +10:00
Brecht Van Lommel
8b85c04832 Fix Cycles OSL compiler warning after voronoi changes
After parameter name conflicting with builtin normalize function.
2023-06-13 19:51:49 +02:00
Hoshinova
144ad4d20b Nodes: add Fractal Voronoi Noise
Fractal noise is the idea of evaluating the same noise function multiple times with
different input parameters on each layer and then mixing the results. The individual
layers are usually called octaves.
The number of layers is controlled with a "Detail" slider.
The "Lacunarity" input controls a factor by which each successive layer gets scaled.

The existing Noise node already supports fractal noise. Now the Voronoi Noise node
supports it as well. The node also has a new "Normalize" property that ensures that
the output values stay in a [0.0, 1.0] range. That is except for the F2 feature where
in rare cases the output may be outside that range even with "Normalize" turned on.

How the individual octaves are mixed depends on the feature and output socket:
- F1/Smooth F1/F2:
  - Distance/Color output:
    The individual Distance/Color octaves are first multiplied by a factor of
    `Roughness ^ (#layers - 1.0)` then added together to create the final output.
  - Position output:
    Each Position octave gets linearly interpolated with the combined output of the
    previous octaves. The Roughness input serves as an interpolation factor with
    0.0 resutling in only using the combined output of the previous octaves and
    1.0 resulting in only using the current highest octave.
- Distance to Edge:
  - Distance output:
    The Distance octaves are mixed exactly like the Position octaves for F1/Smooth F1/F2.

It should be noted that Voronoi Noise is a relatively slow noise function, especially
at higher dimensions. Increasing the "Detail" makes it even slower. Therefore, when
optimizing a scene one should consider trying to use simpler noise functions instead
of Voronoi if the final result is close enough.

Pull Request: https://projects.blender.org/blender/blender/pulls/106827
2023-06-13 09:18:12 +02:00
Lukas Stockner
888bdc1419 Cycles: Remove MultiGGX code, replace with albedo scaling
While the multiscattering GGX code is cool and solves the darkening problem at higher roughnesses, it's also currently buggy, hard to maintain and often impractical to use due to the higher noise and render time.

In practice, though, having the exact correct directional distribution is not that important as long as the overall albedo is correct and we a) don't get the darkening effect and b) do get the saturation effect at higher roughnesses.

This can simply be achieved by adding a second lobe (https://blog.selfshadow.com/publications/s2017-shading-course/imageworks/s2017_pbs_imageworks_slides_v2.pdf) or scaling the single-scattering GGX lobe (https://blog.selfshadow.com/publications/turquin/ms_comp_final.pdf). Both approaches require the same precomputation and produce outputs of comparable quality, so I went for the simple albedo scaling since it's easier to implement and more efficient.

Overall, the results are pretty good: All scenarios that I tested (Glossy BSDF, Glass BSDF, Principled BSDF with metallic or transmissive = 1) pass the white furnace test (a material with pure-white color in front of a pure-white background should be indistinguishable from the background if it preserves energy), and the overall albedo for non-white materials matches that produced by the real multi-scattering code (with the expected saturation increase as the roughness increases).

In order to produce the precomputed tables, the PR also includes a utility that computes them. This is not built by default, since there's no reason for a user to run it (it only makes sense for documentation/reproducibility purposes and when making changes to the microfacet models).

Pull Request: https://projects.blender.org/blender/blender/pulls/107958
2023-06-05 02:20:57 +02:00
Chris Blackbourn
35eea10581 Cleanup: format 2023-06-05 12:14:20 +12:00
Lukas Stockner
f4708831ea Fix Principled Hair Absorption Coefficient when using OSL
The additional SocktType::VECTOR argument was being interpreted as flags,
which caused the OSL compiler to skip the input (since the Vector type enum
happens to align with the INTERNAL flag), which caused the OSL shader to
always use the hardcoded default absorption regardless of what was entered.
2023-06-05 01:35:19 +02:00
Lukas Stockner
8cde7d8f8a Cycles: Merge Anisotropic BSDF node into Glossy BSDF node
Used to be https://archive.blender.org/developer/D17123.

Internally these are already using the same code path anyways, there's no point in maintaining two distinct nodes.

The obvious approach would be to add Anisotropy controls to the Glossy BSDF node and remove the Anisotropic BSDF node. However, that would break forward compability, since older Blender versions don't know how to handle the Anisotropy input on the Glossy BSDF node.

Therefore, this commit technically removes the Glossy BSDF node, uses versioning to replace them with an Anisotropic BSDF node, and renames that node to "Glossy BSDF".

That way, when you open a new file in an older version, all the nodes show up as Anisotropic BSDF nodes and render correctly.

This is a bit ugly internally since we need to preserve the old `idname` which now no longer matches the UI name, but that's not too bad.

Also removes the "Sharp" distribution option and replaces it with GGX, sets Roughness to zero and disconnects any input to the Roughness socket.

Pull Request: https://projects.blender.org/blender/blender/pulls/104445
2023-05-18 23:12:20 +02:00
Campbell Barton
6859bb6e67 Cleanup: format (with BraceWrapping::AfterControlStatement "MultiLine") 2023-05-02 09:37:49 +10:00
Alaska
cff94a808e Fix #106706: fireflies with Nishita sky sun sampling at certain angles
Due to floating point differences between importance sampling and
texture evaluation, disagreeing on whether or not a ray lies within
the sun disc.

* Use the same input values for geographical_to_direction() in
  sky_radiance_nishita() and kernel_data.background.sun.
* The mathematical operations in pdf_uniform_cone() were adjusted to
  match sky_radiance_nishita().

Pull Request: https://projects.blender.org/blender/blender/pulls/106764
2023-04-17 17:29:27 +02:00