Commit Graph

34 Commits

Author SHA1 Message Date
Clément Foucault
fe213f80a4 GPU: Shader: Make info files generated
This is the first step of moving the create infos
back inside shader sources.

All info files are now treated as source files.
However, they are not considered in the include tree
yet. This will come in another following PR.

Each shader source file now generate a `.info` file
containing only the create info declarations.

This renames all info files so that they do not
conflict with their previous versions that were
copied (non-generated).

Pull Request: https://projects.blender.org/blender/blender/pulls/146676
2025-09-25 10:57:02 +02:00
Clément Foucault
bb8e987904 GPU: Simplify matrix lib to reduce dead code
This greatly reduce shader compilation time on some systems.

Pull Request: https://projects.blender.org/blender/blender/pulls/146100
2025-09-15 12:07:26 +02:00
sentharn
69610383b9 Fix #138301: Rename GLSL "select" for Intel GPUs
The GLSL processor appears to dislike a member named "select" when a function named "select" exists.

The member has been renamed to object_select to avoid collisions.

Pull Request: https://projects.blender.org/blender/blender/pulls/138466
2025-05-06 19:42:09 +02:00
Clément Foucault
82dd9f68a4 Fix: Overlay: Compilation error on OpenGL
Caused by reserved `active` keyword in GLSL.
2025-04-30 12:44:00 +02:00
Clément Foucault
7714998537 Overlay: Remove macros for globals uniform buffer access
Pull Request: https://projects.blender.org/blender/blender/pulls/138068
2025-04-30 09:55:52 +02:00
Clément Foucault
3f11d16501 Cleanup: DRW: Make all shader resource snake case
This make sure that the DRW folder is compliant to our codestyle.

Pull Request: https://projects.blender.org/blender/blender/pulls/137673
2025-04-24 12:50:45 +02:00
Clément Foucault
3b3a5731df GPU: Shader: Change vector and matrix type to use blender convention
This unify the C++ and GLSL codebase style.

The GLSL types are still in the backend compatibility
layers to support python shaders. However, the C++
shader compilation layer doesn't have them to enforce
correct type usage.

Note that this is going to break pretty much all PRs
in flight that targets shader code.

Rel #137261

Pull Request: https://projects.blender.org/blender/blender/pulls/137369
2025-04-14 13:46:41 +02:00
Clément Foucault
bb52754652 GPU: Use f suffix for float literals
They are actually already some literals with the `f` suffix
that are in our shader codebase and we never had problem in
the past 5 years (or even 8 years).

So I think it is safe to do and improves convergence of codestyles.

Pull Request: https://projects.blender.org/blender/blender/pulls/137352
2025-04-11 18:28:45 +02:00
Clément Foucault
bb2d123fbd Cleanup: DRW: Remove ObjectInfos legacy GLSL macros
_No response_

Pull Request: https://projects.blender.org/blender/blender/pulls/135542
2025-03-06 11:06:26 +01:00
Clément Foucault
9bddb57960 Cleanup: DRW: Relace drw_view macros by function calls 2025-03-05 15:31:35 +01:00
Clément Foucault
5916c39fa4 Cleanup: DRW: Simplify resource id and custom id 2025-03-05 15:31:35 +01:00
Clément Foucault
3f1289836c Merge branch 'blender-v4.4-release' 2025-03-03 18:58:37 +01:00
Clément Foucault
446ad3ba13 Fix #135246: Overlay: Loose wire disapears when line antialias is off
This was caused by the normals not being available (default to
`vec3(0)`) which produced `NaN`s down the line after the
unsafe normalize. Changing to `safe_normalize` fixes the issue.
2025-03-03 18:58:14 +01:00
Clément Foucault
27c20aaae7 Overlay: Add support for CPP shader compilation
Rel #127983

Also removes some unused shaders.

Pull Request: https://projects.blender.org/blender/blender/pulls/135034
2025-02-24 16:17:18 +01:00
Clément Foucault
f8195e0bb4 Fix: Overlay: Broken shader compilation
Caused by the changes in UBO members.
This removes the duplicated lib used by overlay
and reuse the same side clip plane UBO mechanism
as workbench.
2025-02-19 17:46:47 +01:00
Clément Foucault
7a98a459ef Fix #134011: Overlay: Loose wires object color in selection not visible
The changes from 29356e2bf7
fixed a readability issue with loose wire not being as prominent as
regular surface wireframe.

But also added a regression where the object color wireframe mode
made the object color imperceivable when the object is selected.

This commit fixes the issue by setting the facing factor to 0.5 for
loose wires. This way, both the theme color and object color wireframe
more are blended enough to be distinguishable and still retain the
object color hint.
2025-02-05 14:25:46 +01:00
Clément Foucault
6f9dedcdc4 Fix #134011: Overlay: Wireframe with object color isn't shown selected
This was an oversight and the shader was using the old API.
2025-02-04 19:19:55 +01:00
Clément Foucault
aa8769599c Fix #133775: Overlay: curve attribute is not showing any color in viewport
The curves wireframes should not have any offset applied to them.
This avoid the attribute overlay failling the equal depth tests.
2025-02-03 14:25:00 +01:00
Clément Foucault
cfd5d9e3ad Fix #132895: Overlay: Dashed/flickering wireframe overlay on solid shading
This add back the NDC offset that was present in the legacy overlay.

But instead of adding a new view for it, we add `ndc_offset_factor`
to `State` to simplify wire offseting

Instead of modifying the projection matrix, we compute the unit
offset and pass it to the shader which choose the appropriate
factor to apply to the vertex position.

The value is put inside `State` so that it can be referenced
easily by multiple overlays.
Later on (once we move the global UBO inside Overlay) we can
move this to a UBO.

This only implements it for wireframe and edit mesh vert and
edges.

Note: that there seems to be some code duplication with the
edit mesh vertex code. That's to be tackled in another commit.

Pull Request: https://projects.blender.org/blender/blender/pulls/133433
2025-01-23 18:08:20 +01:00
Clément Foucault
1ac4651778 Cleanup: DRW: Remove legacy common_view_lib.glsl
No functional changes. Only moving and renaming stuff.

Pull Request: https://projects.blender.org/blender/blender/pulls/131558
2025-01-23 18:06:22 +01:00
Miguel Pozo
b295df7345 Refactor: Overlay: Port "next" shaders declarations to static CreateInfos
Use static CreateInfos for Overlay-Next shaders using a similar approach to Workbench shader variations.

Remove unused infos and shader sources.
Remove the `gpu_shader_create_info_get_unfinalized_copy` workaround.

Pull Request: https://projects.blender.org/blender/blender/pulls/131514
2024-12-12 23:05:00 +01:00
Clément Foucault
29356e2bf7 Fix: Overlay-Next: Loose edges is drawn with less intensity when selected
This was caused by the fresnel effect darkening the selection
color when there was no normal attribute available.
Now default to no darkening when no attribute is available.
2024-11-20 18:25:59 +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
Clément Foucault
05deb10405 Fix: Overlay: Intel driver hang caused by shader compilation
Thanks @xavierh for the fix.

Fix #126812
2024-09-04 13:44:42 +02:00
Clément Foucault
86e9254a63 Overlay-Next: Wireframe
Straightforward port.

Left out particle hair to a separate patch for consistency
and simplicity.

Grease Pencil is also missing but that's also missing in
main.

Rel #102179

Pull Request: https://projects.blender.org/blender/blender/pulls/126242
2024-08-19 12:31:08 +02:00
Clément Foucault
c42380c633 Overlay-Next: Outline
Straightforward port.

Only the dupli object optimization and the resource handle
deduplication are left as todos.

Marked areas that are against design to be fixed.

Rel #102179

Pull Request: https://projects.blender.org/blender/blender/pulls/126152
2024-08-12 15:29:20 +02:00
Campbell Barton
3082037743 Cleanup: spelling in comments 2023-09-03 16:15:01 +10:00
Gilberto Rodrigues
1f4c7a36df Wireframe color option for all shading modes
Enables three options of wireframe color for all shading modes: theme color, object color
and random color.  Previously this was exclusive to the wireframe shading mode.

Pull Request: https://projects.blender.org/blender/blender/pulls/111502
2023-08-28 11:04:40 +02:00
Campbell Barton
0148293520 License headers: add SPDX licenses for '*.glsl' files
When GLSL sources were first included in Blender they were treated as
data (like blend files) and had no license header.
Since then GLSL has been used for more sophisticated features
(EEVEE & real-time compositing)
where it makes sense to include licensing information.

Add SPDX copyright headers to *.glsl files, matching headers used for
C/C++, also include GLSL files in the license checking script.

As leading C-comments are now stripped,
added binary size of comments is no longer a concern.

Ref !111247
2023-08-24 10:57:03 +10:00
Germano Cavalcante
1380ee74ff Overlay: use edge-connected polygons to calculate wireframe factor
Use the dot product of the normal of the two polygons connected to the
edge to calculate the edge factor.

This fixes #90641 and #102545 and ensures more predictable results for
boundary and non-manifold edges.

Co-authored-by: Germano Cavalcante <mano-wii>
Pull Request: https://projects.blender.org/blender/blender/pulls/105352
2023-04-03 16:22:41 +02:00
Clément Foucault
70b35c7ad0 Overlay: Use global viewport size instead of DRWView one
This is part of the effor to simplify the View struct in order to implement
multiview rendering.
2022-10-07 12:43:10 +02:00
Clément Foucault
2b806cb955 Cleanup: DRW: Remove drw_view renaming MACROS 2022-06-27 12:46:47 +02:00
Clément Foucault
c15e913df8 Cleanup: DRW: Added overlay_ prefix to all *.glsl files in overlay/shaders
This is needed to avoid potential naming collision with other engines
2022-06-02 21:08:05 +02:00