Commit Graph

4604 Commits

Author SHA1 Message Date
Leon Schittek 899d723da8 Fix: Display nodelinks consistently across different UI scales
Adjust the width, dash length and amount of anti-aliasing of node links
so they look the same independent of the UI scaling.

Adding another parameter to the shader exceeded the limit of 16
attributes. Therefore the parameters to describe the dashes (length,
factor, alpha) are passed in together as a vector.

Ref  #102919

Pull Request: https://projects.blender.org/blender/blender/pulls/111270
2023-08-22 19:24:07 +02:00
Jeroen Bakker 47b431d3b6 Fix: Use correct byte size for GPU_DEPTH_COMPONENT24
Every depth component has a trailing byte for alignment.
So it should be 4 bytes, not 3 bytes.
2023-08-22 14:41:55 +02:00
Jeroen Bakker d9ae608c87 Fix: Crash when using Vulkan backend.
Command buffer was not availble at the time dummy buffers are
initialized. Resulting in undefined behavior.
2023-08-22 13:46:48 +02:00
Jeroen Bakker 4ebd7d84d1 Vulkan: Bind Dummy Vertex Attributes
Batches don't always provide all required resources for a shader.
This can happen when the resource is defined in the shader, but
not used in a specific variant. The definition is still there and
needs to be filled.

This PR adds a dummy buffer to fill the missing attributes.
It also fixes an issue when using vertex attributes that
uses multiple binding locations (mat4).

Pull Request: https://projects.blender.org/blender/blender/pulls/111350
2023-08-22 13:35:01 +02:00
Jeroen Bakker 2af2a11651 Vulkan: Use Correct Image Aspects
Depending on the usage of an image/image view different image aspect
requirements need to be used. When changing the layout of an image
all aspects needs to be included. When using it as a sampler or
framebuffer attachment only one aspect can be used.

This change also remove duplicated code when creating image views.

Pull Request: https://projects.blender.org/blender/blender/pulls/111349
2023-08-22 11:00:43 +02:00
Alaska 7f65080ab4 Fix #111277: NaN in Vector Displacement leading to render errors
Fixes NaN in Vector Displacement node caused by the normalization of
0, 0, 0 vectors.

This fixes both visual rendering issues and an "illegal address" error
on the GPU. The "illegal address" error came from the Light Tree
Sampling code not handling the NaN normals well, leading to weird code
paths being taken, eventually leading to a kernel_assert and a
user facing illegal address error.

Pull Request: https://projects.blender.org/blender/blender/pulls/111294
2023-08-21 15:22:03 +02:00
Jeroen Bakker 785e03b13f Cleanup: Reduce VKDebug Messenger Complexity
Reduces the complexity of VKDebug messenger_callback.
2023-08-21 15:03:33 +02:00
Jeroen Bakker 9df5f2c495 Vulkan: Indirect Drawing
This PR implements indirect drawing for the Vulkan backend. Indirect
drawing is a requirement for workbench-next.

NOTE: that this is one of multiple changes needed to get to the same
support level. With this patch only objects at the center of the world
are drawn correctly.

Pull Request: https://projects.blender.org/blender/blender/pulls/111334
2023-08-21 08:55:55 +02:00
Campbell Barton 33a05725be Cleanup: spelling in comments 2023-08-21 10:05:45 +10:00
Campbell Barton 20b4a77872 datatoc: exclude the initial C-style comment from GLSL/MSL/Cuda files
Add optional argument `STRIP_LEADING_C_COMMENTS` to CMake macros:
data_to_c_simple & data_to_c.

Strip leading C-style comments that don't bloat binary size.
Comments are replaced with blank lines so line numbers in error messages
match. Reduces Blender's binary size by ~70kb.
2023-08-19 17:57:12 +10:00
Campbell Barton 63c1a26069 Cleanup: move GLSL comments to the file start
This has the benefit that leading comments may be stripped,
reducing the binary size (not yet supported).
2023-08-19 17:56:48 +10:00
Campbell Barton 04bf0f3eb6 License headers: add SPDX copyright entries for '*.msl' files 2023-08-19 17:41:14 +10:00
Campbell Barton add2a656da Cleanup: spelling, use C-style in GLSL 2023-08-19 17:13:05 +10: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
Jeroen Bakker 82c1b9f684 Vulkan: Remove Unneeded Workaround for Shader Interfaces
All shaders have been patched and an error will be generated when using
incompatible shaders, no need to have workaround in the code anymore.
2023-08-18 08:57:37 +02:00
Jeroen Bakker 8477f62ba1 Vulkan: Detect Vulkan Incompatibility When Running OpenGL/MTL
Now that all shaders have been converted to be Vulkan Compatible it is
safe to test for incompatibility when running in OpenGL or MTL.

This detection is only done when blender is compiled in debug mode.
2023-08-18 08:48:22 +02:00
Omar Emara 110cb5d0d5 BLI: Add square function
This patch adds the square function for both float and vector math BLI
libraries. It also renames the corresponding GLSL function for
compatibility.

Pull Request: https://projects.blender.org/blender/blender/pulls/111217
2023-08-17 15:05:52 +02:00
Jeroen Bakker 53396816e4 Vulkan: Make Polyline Shaders Vulkan Compatible
Splitting interface stages based on the interpolation of its
attributes.

Then naming convention that have been used:

* use `interp` as instance name when using smooth interpolation
* use `interp_noperspective` when using no perpective interpolation
* use `interp_flat` when using flat interpolation

The same suffix will be added to the struct names.
The naming convention will be added to the GLSL code style and
applied to other shaders as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/111210
2023-08-17 11:31:10 +02:00
Jeroen Bakker 074f10470c Vulkan: Add Workaround for Mixed Interpolation Attributes
shaderc generates an error when a struct containing an int type
isn't qualified as flat. We work around this issue by changing the
interpolation mode to flat during code generation.

Pull Request: https://projects.blender.org/blender/blender/pulls/111211
2023-08-17 10:53:05 +02:00
Jeroen Bakker f44447a628 Vulkan: Use Correct Interpolation Qualifier in Stage Interfaces
This PR cleans up the Stage Interface code generation and use the
correct interpolation qualifier. This is a cleanup/fix before we can
start converting shaders stage interfaces to be compatible with vulkan.

Ref: #111138 for more information about vulkan compatibility
Pull Request: https://projects.blender.org/blender/blender/pulls/111207
2023-08-17 09:40:34 +02:00
Jeroen Bakker 6f9c3b1bd5 Vulkan: Report Incompatible Shaders
A difference was detected between stage interfaces between OpenGL and Vulkan
that are not compatible with our current API.

**OpenGL**

In OpenGL an stage interface struct can have different interpolation qualifiers
per attribute.

```glsl
struct MyStageInterface {
    smooth vec4 color;
    flat int face_flag;
};
layout(..) MyStageInterface interp;
```

**Vulkan**

In vulkan the interpolation qualifier isn't supported on attribute
level and needs to be added to the struct.

```glsl
struct MyStageInterface {
    vec4 color;
};
struct MyStageInterface_flat {
    int face_flag;
};
layout(..) smooth MyStageInterface interp;
layout(..) flat MyStageInterface_flat interp_flat;
```

This patch reports shaders that are incompatible with Vulkan so they can be
patched. Report is only done in debug mode and when using the vulkan backend.
After all shaders are patched an error will be raised so developers will
known immediately when incompatibility are created.

Making the shaders compatible and adding the error will be done in future
patches.

**Python**

Via Python gpu module (gpu.types.GPUShaderCreateInfo) it isn't possible
to construct an incompatible shader as instance names cannot be set
via the API. So this isn't a breaking change.

Pull Request: https://projects.blender.org/blender/blender/pulls/111138
2023-08-17 08:59:03 +02:00
Campbell Barton b1b20bea7b Fix Shader::print_log not handling warnings
Severity::Error was checked twice.
2023-08-17 16:53:08 +10:00
Jeroen Bakker bbe4f6cf74 Fix: Compilation Error When Compiling with Vulkan
This PR fixes an compilation error where sstream used to be included
on a higher level, but has been removed and we need to include them
where they are actually used.

This wasn't detected as most developers don't have the vulkan backend
active.

Pull Request: https://projects.blender.org/blender/blender/pulls/111203
2023-08-17 08:24:29 +02:00
Aras Pranckevicius acbd952abf Cleanup: fewer iostreams related includes from BLI/BKE headers
Including <iostream> or similar headers is quite expensive, since it
also pulls in things like <locale> and so on. In many BLI headers,
iostreams are only used to implement some sort of "debug print",
or an operator<< for ostream.

Change some of the commonly used places to instead include <iosfwd>,
which is the standard way of forward-declaring iostreams related
classes, and move the actual debug-print / operator<< implementations
into .cc files.

This is not done for templated classes though (it would be possible
to provide explicit operator<< instantiations somewhere in the
source file, but that would lead to hard-to-figure-out linker error
whenever someone would add a different template type). There, where
possible, I changed from full <iostream> include to only the needed
<ostream> part.

For Span<T>, I just removed print_as_lines since it's not used by
anything. It could be moved into a .cc file using a similar approach
as above if needed.

Doing full blender build changes include counts this way:
- <iostream> 1986 -> 978
- <sstream> 2880 -> 925

It does not affect the total build time much though, mostly because
towards the end of it there's just several CPU cores finishing
compiling OpenVDB related source files.

Pull Request: https://projects.blender.org/blender/blender/pulls/111046
2023-08-16 09:51:37 +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
Campbell Barton e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Jeroen Bakker 616e0c8c1d Vulkan: Set Geometry Shader Capability
Vulkan already used geometry stages, but it wasn't set as backend
capability. This resulted that the shader builder didn't validate
shaders that uses geometry stages.

Pull Request: https://projects.blender.org/blender/blender/pulls/111139
2023-08-15 15:53:56 +02:00
Jeroen Bakker d20f26aeb6 Fix: Memory Reserve Issue in Vulkan/Std140
This PR solves a memory reserve issue when a nvec3 was followed by
a int, bool, float.

Also adds a debug_print method to the push constants for checking
the structure against data in renderdoc.

Pull Request: https://projects.blender.org/blender/blender/pulls/111109
2023-08-15 14:16:26 +02:00
Jeroen Bakker ab3ae2be4d Fix: Vulkan Use Resource After Free
When immediate mode is used with a temp texture the
draw command was executed after the texture was freed.

This PR ensures that the draw command is executed before
the texture is freed.

Pull Request: https://projects.blender.org/blender/blender/pulls/111111
2023-08-15 14:15:46 +02:00
Jeroen Bakker dd4ab50065 GPU: Add Dummy Backend For Unsupported Platforms
With the introduction of metal and vulkan we use a different
GPU backend selection which broke the dialog box for unsupported
platforms.

Blender asserted and segfaulted before the dialog was being shown
to the user.

This patch solves this by introducing a dummy GPU backend in case no
GPU backend was supported by OpenGL, Metal and Vulkan Backend.

It also adds the showMessageBox to GHOST_SystemCocoa.

Related to #110335

Pull Request: https://projects.blender.org/blender/blender/pulls/110919
2023-08-15 14:15:12 +02:00
Clément Foucault dd9a92785a Metal: Fix incorrect texture 2D array read
Authored by Apple: Michael Parkin-White
2023-08-14 23:32:44 +02:00
Jason Fielder ca527efb9f Metal: Ensure MTLBatch uses context bound shader
Previously the shader associated with a batch was
assigned separately. This meant on occasion, the
incorrect shader was used with the Metal backend.
Updating the shader fetch to use the context bound
shader instead of the batch shader member as per
OpenGL/Vulkan backends.
Also include state change check to be consistent
with OpenGL.

Authored by Apple: Michael Parkin-White

Co-authored-by: Michael Parkin-White <mparkinwhite@apple.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/111112
2023-08-14 15:56:12 +02:00
Clément Foucault d844c5a13a Metal: Add support for Multi-Viewport
This seems to work but there is an issue with fragment
shader not getting the correct value.

Authored by Apple: Michael Parkin-White
2023-08-13 23:46:53 +02:00
Clément Foucault c7dce76619 Metal: Various fixes
Authored by Apple: Michael Parkin-White
2023-08-13 23:42:06 +02:00
Clément Foucault 743d78461f GPU: Make test compile without OpenGL 2023-08-13 23:38:07 +02:00
Hans Goudey 9804b2244a Cleanup: Make sculpt face visibility test inline
This simple function just performed a null check and an array lookup.
Just writing it in the few places its used works fine too, and avoiding
the function call per triangle can improve and make the check clearer.

Also, avoiding the abstraction makes the "node fully visible" check
when building the PBVH more obvious; that has been refactored here.

Pull Request: https://projects.blender.org/blender/blender/pulls/111072
2023-08-12 23:58:26 +02:00
Jeroen Bakker cbdcc5dfd0 Fix: Compilation Error in Draw Test Cases
Pull Request: https://projects.blender.org/blender/blender/pulls/111035
2023-08-11 08:18:30 +02:00
Aras Pranckevicius d973355b3a Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).

However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.

This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.

Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
  to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).

Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.

Pull Request #110944
2023-08-10 14:51:40 +03:00
Clément Foucault 15124fe490 GPU: Avoid silent errors during shader compilation
To this end, replace some printf by std::cerr.
2023-08-09 18:15:36 +02:00
Jason Fielder 2367ed2ef2 macOS: Enable support for EDR rendering
Add a High Dynamic Range option in the Color Management > Display panel.
This enables display of extended color ranges above 1.0 for the 3D
viewport, image editor and render previews.

This requires a monitor that can display HDR colors, and a view
transform designed for HDR output. The Standard view transform works,
but Filmic does not as it was designed to bring values into the 0..1
range for SDR displays.

This patch is limited to allowing the display to visualize extended
colors, but does not include future looking work to better integrate HDR
into the full workflow.

It is implemented by rendering to high bit-depth texture formats for
the user interface, and uncapping the color range in color management.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/105662
2023-08-09 14:25:15 +02:00
Clément Foucault 983ff8e616 GPU: Framebuffer: Add multi viewport support
This add the possibility to define different
viewports inside a single framebuffer and
let the vertex shader decide which viewport
to render to.

This only contain the GL and VK implementation.
The Vulkan implementation works but still
has a validation error related to shader features
and extension. The test passes nonetheless.

Pull Request: https://projects.blender.org/blender/blender/pulls/110923
2023-08-08 17:12:49 +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
Jeroen Bakker 6273a2dca4 GPU: Disable Multi-Bindings for AMD Official Drivers
AMD official driver reports that they support multi-bindings, but
in the cases we are using it it fails. This is noticable in Eevee-
next where the shadows aren't rendered.

This fix disables multi-bindings for images for AMD Official drivers
n all OS's. Textures will still use multi-bindings.

Pull Request: https://projects.blender.org/blender/blender/pulls/110882
2023-08-07 14:47:46 +02:00
Jacques Lucke 607d203b98 Cleanup: fix compilation errors and warnings 2023-08-05 08:31:31 +02:00
Campbell Barton bf2b1f7e01 Cleanup: simplify enum typedefs 2023-08-05 14:22:48 +10:00
Campbell Barton 9ea8477c23 Cleanup: various non-functional C++ changes 2023-08-05 13:57:29 +10:00
Campbell Barton 7f34ad736a Cleanup: spelling in comments 2023-08-05 13:54:25 +10:00
Hans Goudey 07019e7ef5 Cleanup: Remove more struct keywords from C++ headers 2023-08-04 22:47:29 -04:00
Hans Goudey ffe4fbe832 Cleanup: Move editors headers to C++
See #103343

Pull Request: https://projects.blender.org/blender/blender/pulls/110820
2023-08-05 02:57:52 +02:00
Hans Goudey c15d391e86 Cleanup: Various cleanups in newly C++ headers
Mostly remove unnecessary struct and typedef keywords.
Move a few more small wm headers to C++ as well.
2023-08-04 17:55:14 -04:00