Commit Graph

252 Commits

Author SHA1 Message Date
Alaska
8ed69341d0 Shader: Expose light path "is volume scatter ray" in UI
This commit adds the "is volume scatter" output to the light path node
in the shader editor.

All the funcitonal code for this feature already exists in Cycles SVM
and OSL, but the output wasn't exposed on the node.

EEVEE does not support the feature, so it's output will
always be zero.

Pull Request: https://projects.blender.org/blender/blender/pulls/134343
2025-02-12 15:45:04 +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
Clément Foucault
10c0b19213 Cleanup: GPUMaterial: Remove leftover EEVEE Legacy code 2025-01-28 17:48:34 +01:00
Brecht Van Lommel
5e02b4e6f1 EEVEE: Use OpenColorIO for luminance
Color to grayscale conversions should take into account the colorspace,
and these are considered to be in scene linear colorspace.

Note the RBG to BW node implementation is used for implicit conversions,
so that is covered as well.

No change with the default configuration.

Pull Request: https://projects.blender.org/blender/blender/pulls/133368
2025-01-21 18:05:56 +01:00
Clément Foucault
9c0321ae9b Metal: Simplify MSL translation
Move most of the string preprocessing used for MSL
compatibility to `glsl_preprocess`.

Enforce some changes like matrix constructor and
array constructor to the GLSL codebase. This is
for C++ compatibility.

Additionally reduce the amount of code duplication
inside the compatibility code.

Pull Request: https://projects.blender.org/blender/blender/pulls/128634
2024-10-07 12:54:10 +02:00
Clément Foucault
7e5bc58649 GPU: Change GLSL include directive
This changes the include directive to use the standard C preprocessor
`#include` directive.

The regex to applied to all glsl sources is:
`pragma BLENDER_REQUIRE\((\w+\.glsl)\)`
`include "$1"`

This allow C++ linter to parse the code and allow easier codebase
traversal.

However there is a small catch. While it does work like a standard
include directive when the code is treated as C++, it doesn't when
compiled by our shader backends. In this case, we still use our
dependency concatenation approach instead of file injection.

This means that included files will always be prepended when compiled
to GLSL and a file cannot be appended more than once.

This is why all GLSL lib file should have the `#pragma once` directive
and always be included at the start of the file.

These requirements are actually already enforced by our code-style
in practice.

On the implementation, the source needed to be mutated to comment
the `#pragma once` and `#include`. This is needed to avoid GLSL
compiler error out as this is an extension that not all vendor
supports.

Rel #127983
Pull Request: https://projects.blender.org/blender/blender/pulls/128076
2024-10-04 15:48:22 +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
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
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
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
be50c96c00 Fix #125643: Mismatch between Cycles EEVEE Vector Math Refract
Fixes a mismatch between Cycles and EEVEE when rendering a
Vector Math node in Refract mode with a normal vector of 0,0,0.

This mismatch first appeared after 8650068f0c which changed the
behaviour in Cycles, but not EEVEE.

Pull Request: https://projects.blender.org/blender/blender/pulls/125644
2024-07-30 17:33:39 +02:00
Weizhen Huang
c7c55894e4 Fix: EEVEE principled coat has tint when the weight is zero
caused by 26eb5d9899

Pull Request: https://projects.blender.org/blender/blender/pulls/124856
2024-07-17 13:54:26 +02:00
Weizhen Huang
3fcd80db68 Fix #124621: EEVEE closure reservoir sampling not considering color weight
color was not taken into consideration when picking a closure using
reservoir sampling, giving closures with dark color much higher weights
than they should have.
This fix multiplies the weight by the average color when picking the
closure, similar as what has been done in principled BSDF.

Pull Request: https://projects.blender.org/blender/blender/pulls/124730
2024-07-15 17:00:51 +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
Lukas Stockner
26eb5d9899 EEVEE: Adapt Principled BSDF to closure sampling
With the new closure approach, the code can be simplified and cleaned up quite
a bit.

This also removes four parameters, which is helpful for future additions (!123616)
since the parameter limit appears to be reached.

Pull Request: https://projects.blender.org/blender/blender/pulls/123643
2024-06-24 00:20:30 +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
Clément Foucault
ff03ab4d08 Fix: EEVEE: Overblur of textures because of TAA
This was a missing block of the TAA implementation.
TAA jitter and reprojection have a tedency to soften
the texture. Add a 1.5 bias to make them a bit sharper.

Note that this is a bit different than the usual TAA
blurring. In final render we don't do reprojection
so it is only because the texture filter (box filter
from the LOD) is applied at the same time than our pixel
filter (blackmann-harris). It is less noticeable than
the normal TAA blur, but still blurs ~2px instead of
1.5px.
2024-06-18 19:31:47 +02:00
Clément Foucault
6d375cf7f0 Fix: EEVEE: Wrong thickness for rotated objects
The previous code was using matrix multiplication to
get the local thickness to world thickness.

The correct way is to multiply the local thickness
by the scale of the object (length of each columns
of the object_to_world matrix).
2024-06-17 19:12:24 +02:00
Miguel Pozo
fb5faf3305 FIx #122915: Diffuse normal input isn't normalized automatically 2024-06-11 16:51:04 +02:00
Vitaljok
14f9ae90c2 EEVEE: fixing vector displacement
Fix for #121890

The image shows testing results with "green" texture. It is expected that
all vectors are displaced along Y axis.
Cases are "no displacement", "tangent", "object" and "world" spaces.

Results are consistent with Cycles.

Pull Request: https://projects.blender.org/blender/blender/pulls/122376
2024-05-28 21:20:54 +02:00
Hoshinova
de6ff6eb0a Fix #121969: Noise texture outputs 0 with coordinates beyond 8.40*10^6
One of the properties of Perlin noise is that it always evaluates to 0.0
when not normalized (or 0.5 when normalized) when the input consists of
only whole integers in all vector components.

Blender's Perlin noise implementation uses single precision floats with
a machine epsilon of 1.19e-07 meaning that for numbers that are greater
than 1/(1.19e-07) = 8.40e6 there mantissa doesn't have any bits left to
store a rational part of the number, effectively meaning that any number
greater than 8.40e6 is a whole integer as far as Blender is concerned.
Therefore when evaluating Perlin noise for any coordinates greater than
that it always results in 0.0 (or 0.5 when normalized).

This fix works as follows: If the original input number is larger than
1.0e6 it is offset by 0.5 after it underwent modulo, which always outputs
numbers in a [0.0, 1.0e5) range leaving the mantissa room for a rational
part. This way the quantization error still persists however the outputs
are random again instead of a constant 0.0.

Pull Request: https://projects.blender.org/blender/blender/pulls/122112
2024-05-27 12:48:15 +02:00
Vitaljok
2c1238466d Fixing object index value for EEVEE-Next
EEVEE Next uses different bit representation of object index values pushed
to GPU in contrast to EEVEE (Legacy). The fix accounts both approaches.

Fix #121690.

Pull Request: https://projects.blender.org/blender/blender/pulls/121870
2024-05-16 14:37:32 +02:00
Clément Foucault
e63fef6162 Fix: EEVEE-Legacy: Broken Specular BSDF 2024-05-11 17:08:15 +02:00
Clément Foucault
94a83bcf04 EEVEE-Next: Make Specular BSDF work
This removes the ambient occlusion socket as this
have no use in EEVEE-Next.

Add correct material flags for noiseless clear coat
and fix transparency.
2024-05-09 11:59:27 +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
Clément Foucault
e581ba077d Fix: EEVEE-Next: Principled BSDF transmission color applied twice
This was caused by the 2 transmission event approximation we
do for object with non-null thickness. This follows cycles
by using the square root of the color.
2024-04-30 19:32:52 +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
afa66fc628 Shader: Clamp invalid inputs of various BSDF nodes
Clamp some of the inputs of the Glossy BSDF, Glass BSDF, Sheen BSDF,
and Subsurface Scattering nodes to improve consistency between render
engines and to avoid unexpected results.

* Clamp roughness to 0..1
* Clamp subsurface radius to 0..inf
* Clamp colors to 0..inf

Pull Request: https://projects.blender.org/blender/blender/pulls/120390
2024-04-26 17:39:39 +02:00
Clément Foucault
6d347dd5ca Fix: EEVEE-Next: Point cloud macro coliding with voronoi texture
Was caused by macro declaration. Remove the macro
and add another `#if` case for EEVEE-next instead.

Fix #115438
2024-04-24 09:38:32 +02:00
Clément Foucault
c601569702 Fix: EEVEE-Next: Displacement: Revert object scaling on output
This was introduced by f371624b2e
but this breaks the render test. Need another approach to match
cycles with object scaling.
2024-04-18 12:30:03 +02:00
Campbell Barton
f8197098c6 Cleanup: spelling in comments 2024-04-17 14:18:33 +10:00
Clément Foucault
a772c84341 EEVEE-Next: Changes to thickness output
This contains two thing:
- default (nothing connected to socket) uses the bounding box min axis.
- transform the value plugged to the socket to world space.

We arbitrarly choose to output the axis with the minimum extent since
it is the axis along which the object is usually viewed at.

Rel #120384

Pull Request: https://projects.blender.org/blender/blender/pulls/120607
2024-04-15 12:16:51 +02:00
Clément Foucault
fdf5a05bde Fix: EEVEE-Next: Broken shader compilation because of displacement
Oversight inside f371624b2e
2024-04-13 12:57:50 +02:00
Clément Foucault
f371624b2e Fix: EEVEE-Next: Displacement: Wrong output space
The space of the displacement socket on the ouput node
is local space. We now scale it back to world space
as expected by the consumer code.
2024-04-13 12:37:29 +02: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
Jeroen Bakker
f0f911590e EEVEE-Next: Viewport pixel size with up-sampling
EEVEE-Next performes less on integrated GPUs then discrete GPUs.
Most shaders have been analyzed, but there will always be bottlenecks
related to architectural differences.

In order to make EEVEE-Next run smooth on integrated GPUs this change
will implement viewport pixel size option similar to Cycles. The main difference
is that the samples will still be weighted and up-sampled to the final film
resolution. This makes the pixels not look squared in the viewport but will
resolve to something close to the results without up-scaling.

This improves the performance especially on integrated GPUs. The improvement
for discrete GPUs are less noticeable. See here the stats when playing
`rain_restaurant.blend` back on a RAPHAEL_MENDOCINO iGPU.

| Pixel size | Frames per second |
|------------|-------------------|
| 1x         | 0.25 FPS          |
| 2x         | 4.14 FPS          |
| 4x         | 6.90 FPS          |
| 8x         | 9.95 FPS          |

Related to: #114597
See PR for some example images.

Pull Request: https://projects.blender.org/blender/blender/pulls/118903
2024-03-13 12:00:24 +01:00
Jeroen Bakker
e6eecdf614 EEVEE-Next: Voronoi colors are pure emissive
The voronoi texture node only sets the first 3 components of the
color. The alpha value is never set. Normally this is covered
when using it in a shader node, but when directly connected to
the AOV output, the color was stored as a pure emissive color.

This resulted in incorrect colors in the viewport and image renders.

This is a partial fix for #118494

Pull Request: https://projects.blender.org/blender/blender/pulls/118497
2024-02-21 11:32:29 +01:00
Miguel Pozo
ef6b6031de Fix #117123: EEVEE: Broken Specular BSDF
Add missing disable sss flag
2024-01-15 16:57:18 +01:00
Miguel Pozo
31d8a6514f Fix: EEVEE(Legacy): Broken dielectric material shading
sss_radius r and g are already used for occlussion workarounds.
Use only sss_radius.b for flagging sss as disabled.
Regression from 2942147079.
2024-01-10 17:59:20 +01:00
Clément Foucault
ea989ebf94 EEVEE/EEVEE-Next: Split Diffuse and Subsurface closure
Even if related, they don't have the same performance
impact.

To avoid any performance hit, we replace the Diffuse
by a Subsurface Closure for legacy EEVEE and
use the subsurface closure only where needed for
EEVEE-Next leveraging the random sampling.

This increases the compatibility with cycles that
doesn't modulate the radius of the subsurface anymore.
This change is only present in EEVEE-Next.

This commit changes the principled BSDF code so that
it is easier to follow the flow of data.

For legacy EEVEE, the SSS switch is moved to a
`radius == -1` check.
2024-01-09 16:39:17 +13:00
Clément Foucault
ac11ccd2bd EEVEE-Next: Add Translucent BSDF support
This adds support for Translucent BSDF.

This also fixes a bug to allow correct
shadowing.

The input normal had to be set back to
non-inverted in the node function to allow
for correct interpretation of the Normal
by Screen Space Reflections.

This add the necessary optimization
and code deduplication to hybrid deferred
and forward pipeline.

Pull Request: https://projects.blender.org/blender/blender/pulls/116070
2023-12-13 02:19:19 +01:00
Clément Foucault
92bec9af0c Fix EEVEE: Compilation on Metal 2023-11-30 01:10:27 +01:00
Jeroen Bakker
8ae80abe5f Fix: Various Small GLSL Material Tweaks
We should use explicit casting. Although it is not always needed it
is a best practise in order to support the shaders on Metal.

* `float max(float, int)` is not supported on Metal and fails with a compilation error

Pull Request: https://projects.blender.org/blender/blender/pulls/115464
2023-11-27 12:06:28 +01:00
Jason Fielder
9042773d93 GPU: Resolve compilation error in Metal caused by type ambiguity
Recent change in commit 3f778150a9
caused compilation errors in Metal due to type ambiguity. Updating call to
explicitly utilise floats where appropriate.

Authored by Apple: Michael Parkin-White

Co-authored-by: Michael Parkin-White <mparkinwhite@apple.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/115301
2023-11-27 11:50:25 +01:00
Jeroen Bakker
53ebe40ed2 Fix: EEVEE Compiler Issue Emission Shader
Due to recent changes the local variables where not explicitly cast, that failed
when compiling on Metal.

Pull Request: https://projects.blender.org/blender/blender/pulls/115463
2023-11-27 08:46:23 +01:00