Commit Graph

9510 Commits

Author SHA1 Message Date
Jacques Lucke
f442c86197 Depsgraph: improve type safety when getting evaluated or original ID
The goal here is to avoid having to cast to and from `ID` when getting the
evaluated or original ID using the depsgraph API, which is often verbose and not
type safe. To solve this, there are now `DEG_get_original` and
`DEG_get_evaluated` methods which are templated on the type and use a new
`is_ID_v` static type check to make sure it's only used with valid types.

This allows removing quite some verbosity on all the call sites. I also removed
`DEG_get_original_object`, because that does not have to be a special case
anymore.

Pull Request: https://projects.blender.org/blender/blender/pulls/137629
2025-04-17 13:09:20 +02:00
Falk David
012425a0ee Cleanup: Grease Pencil: Anti-Aliasing sample code
Some smaller cleanups in the AA sample code.
2025-04-17 11:47:13 +02:00
Campbell Barton
64f5dee6d7 Cleanup: spelling in comments (make check_spelling_*) 2025-04-17 12:06:12 +10:00
Clément Foucault
f2cfa822da Fix: DRW: Broken or non-deterministic tests
The test_draw_submit_only was broken because of the
empty pass optimization #135875. Making the passes
non-empty fixes the test.

`eevee_surfel_list` has non-deterministic result. This
should be investigated in the future.
2025-04-16 21:48:47 +02:00
Clément Foucault
0b2a178efc Fix: DRW: Uninitialized mutex in tests
Tests were calling the submission mutex without
init. Adding functions to expose only setting
up the submission mutex instead of the full
DRW context (which is uneeded here).
2025-04-16 21:38:19 +02:00
Clément Foucault
92496bbfaf Fix: DRW: Nullptr dereference in tests
This happens because there is no global context set
when running the draw tests. Removing the global
access fixes the issue.
2025-04-16 21:36:13 +02:00
Clément Foucault
5bd572d4fd Cleanup: Overlay: Remove _next in overlay filename
These are not needed anymore since the legacy codebase
is gone.
2025-04-16 20:51:24 +02:00
Clément Foucault
2cc0dad451 Cleanup: Overlay: Remove overlay_private.hh and share uv line style enum 2025-04-16 20:46:14 +02:00
Clément Foucault
0f71bb6c71 GPU: Rename shader_shared.h files to .hh
This makes more sense now that everything is C++.
2025-04-16 20:26:48 +02:00
Clément Foucault
a6fa1b5969 DRW: Rename common_*_lib.glsl to follow module prefix 2025-04-16 20:19:09 +02:00
Clément Foucault
f2025f28e7 DRW: Move fullscreen vertex shader to gpu common
This makes no sense to have in the draw namespace.

Also take the opportunity for making the coordinates
a float2 and rename them to something more descriptive.
2025-04-16 20:09:28 +02:00
Clément Foucault
a798c48d0d Fix: EEVEE: Shadow acnee caused by large objects in the scene
This was caused by the shadow map Z range loosing too much
precision on the large object.

This can be replicated by adding a very large object in the scene.
The normaly un-shadowed objects gets shadowed because the
float precision is not enough to represent their depth correctly.

To fix this, we bias the shadow depth by 2 ULP to make sure that
there is no self shadowing.

This bias has already been there, but was somehow removed because
of other fixes that simingly fixed this issue. But they did not.

Pull Request: https://projects.blender.org/blender/blender/pulls/137555
2025-04-16 00:13:48 +02:00
Clément Foucault
846d88ed17 Fix #137475: Overlay: Empty point cloud crash with geometry nodes
This was caused by an emtpy VBO being bound as
a texture. This is undefined behavior on some implementation.
2025-04-15 17:56:00 +02:00
Clément Foucault
50063c036c Fix: EEVEE: Assert in render
Caused by d354df7483
2025-04-15 17:28:05 +02:00
Clément Foucault
d354df7483 Fix: EEVEE: Missing update from shading popover properties
These properties were triggering a `view_update` call
but this function callback was removed during the
modernization of the DRW module.
2025-04-15 17:16:28 +02:00
Clément Foucault
b01cdf7df2 EEVEE: Remove shadow ray horizon clipping
This make the shadow rays always multiply the lighting,
which can make renders with large light sources darker.

This bias introduced too many light leaking issues. And
these issues are made more visible since the introduction
of 410282e156.

Its first use was to avoid self shadowing artifacts from
large light sources. Since the shading was already
integrated over the visible hemisphere, it made sense
that the shadowing was also in the visible hemisphere.

However this only works if the shading is actually
clipped to the visible hemisphere above the geometric
normal, which might not always be the case.

Given it is better to have self shadowing noise than
light leaking, it is better to just removing this trick.
Self shadow noise can be mitigated by increasing the
sample count or by increasing the terminator bias.
Light leaking, on the other hand, has no known workaround.

Fix #136594

Pull Request: https://projects.blender.org/blender/blender/pulls/137485
2025-04-15 16:38:52 +02:00
Clément Foucault
47d2dffe8c GPU: Shader CodeBase use constexpr instead of const
Do this only when applicable.

This allow better compile time checking in Shader C++ compilation.
Moreover, this allows to have `constexpr` in shared code between
C++ and GLSL.

After investigation the `const` keyword in GLSL has the same
semantic than C/C++.

Rel #137333 and #137446

Pull Request: https://projects.blender.org/blender/blender/pulls/137497
2025-04-15 11:36:53 +02:00
Miguel Pozo
719351a9e6 Fix #137427: Overlay: Darker curve sculpt overlay
Use alpha blend (same as legacy).

Pull Request: https://projects.blender.org/blender/blender/pulls/137480
2025-04-14 17:32:01 +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
9990273d04 GPU: Change Type enum to use lower case values
This is to help for future resource declaration
using macros.

Rel #137261

Pull Request: https://projects.blender.org/blender/blender/pulls/137367
2025-04-11 22:39:01 +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
Miguel Pozo
7554ceba2b Fix: Metal: textureGather
Metal doesn't support the last textureGather parameter.
2025-04-11 17:22:12 +02:00
Miguel Pozo
aafd5b677a Fix #137121: Overlay: Vertex Flickering in X-Ray View
Avoid aliasing and interpolation issues by sampling nearby pixels.

Pull Request: https://projects.blender.org/blender/blender/pulls/137154
2025-04-11 17:06:10 +02:00
Jeroen Bakker
a2338e3eca Fix #137329: Overlay: Cursor not always visible
On certain platforms the 3d cursor wasn't visible. The reason was that
the shader read garbage in `gpu_attr_1_fetch_unorm8` and interpreted the
data to be packed, resulting in loading incorrect colors.

Pull Request: https://projects.blender.org/blender/blender/pulls/137336
2025-04-11 13:59:17 +02:00
Campbell Barton
b2dbfa7d77 Cleanup: spelling in comments, use doxygen comments 2025-04-10 13:02:29 +10:00
Clément Foucault
890e00cecb DRW: DebugDraw: Revamp the module and make it global
- Make the module global and allow usage from anywhere.
- Remove the matrix API for thread safety reason
- Add lifetime management
- Make display linked to the overlays for easy toggling

## Notes
- Lifetime is in redraw. If there is 4 viewport redrawing, the lifetime decrement by 4 for each window redraw. This allows one viewport to be producer and another one being the consumer.
- Display happens at the start of overlays. Any added visuals inside of the overlays drawing functions will be displayed the next redraw.
- Redraw is not given to happen. It is only given if there is some scene / render update which tags the viewport to redraw.
- Persistent lines are not reset on file load.

Rel #137006

Pull Request: https://projects.blender.org/blender/blender/pulls/137106
2025-04-09 21:37:23 +02:00
Miguel Pozo
176865062a Draw: Skip empty passes
Allow detecting passes that can be skipped without side-effects and
don't submit them.
Eases debugging and profiling, and may provide a performance
improvement.

Pull Request: https://projects.blender.org/blender/blender/pulls/135875
2025-04-09 15:34:38 +02:00
Jacques Lucke
93deafd4a3 Refactor: Depsgraph: add const variants of a couple depsgraph query functions
This avoids the need for `const_cast` when using the depsgraph query functions
like `DEG_get_original_id` in many cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/137162
2025-04-08 18:55:22 +02:00
Hans Goudey
42adf00f53 Fix #137098: Crash when saving file in edit mode from python load_post handler
Before accessing the BMesh from BMEditMesh, it should be null checked.

Pull Request: https://projects.blender.org/blender/blender/pulls/137155
2025-04-08 18:00:03 +02:00
Hans Goudey
0b7b2e737f Fix: EEVEE motion blur broken after recent fix
Caused by 36130d5584.
That changed the order of the buffers in the surface batch.
I added an assert here so that won't happen again.

Pull Request: https://projects.blender.org/blender/blender/pulls/137104
2025-04-07 18:04:00 +02:00
Clément Foucault
13bf095c18 Fix #137022: EEVEE: Shadows on reflection planes render incorrectly
This was caused by the cross product changing
sign in view space during planar lightprobe capture.

This can be avoided by making sure the view matrix
doesn't change handedness.

Pull Request: https://projects.blender.org/blender/blender/pulls/137092
2025-04-07 16:27:31 +02:00
Hans Goudey
36130d5584 Fix #136837: Mesh incorrectly renders smooth with GPU subdivision in some cases
Caused by 9b70851d91.
That commit inadvertently switched the order of these definitions. Because the
vertex buffers created by GPU subdivision still have a different format than regular
mesh drawing (the position buffer also includes vertex normals), the order of these
VBOs in the batch matters, since "lnor" attribute can override another.

Pull Request: https://projects.blender.org/blender/blender/pulls/137000
2025-04-05 15:21:48 +02:00
T0MIS0N
24d08e0bae Overlay: Allow drawing UVs in Image Editor in any mode
**Problem**
When using Texture Paint mode, the Image Editor will show a UV Wireframe
to display the active object's UVs. In every other mode, this wireframe
is absent. This is currently a big problem for Sculpt Mode since the
Experimental Texture Paint system is a part of that mode, meaning that
the user can't see their UVs while they paint in Sculpt Mode. This is
also troublesome for users that would like to quickly view an object's
UVs without using Texture Paint Mode.

**Solution**
Since it's useful to be able to view an object's UVs at all times, the
Image Editor should display UV Wireframes in all Object Modes regardless
of the Image Editor's mode. This is the best solution since it means
that future Blender features, that would benefit from having a preview
of an object's UV Wireframes, will automatically have that option since
UV Wireframes are supported in all modes. Also, if a user doesn't want
to see UV Wireframes for any reason, it can be disabled with an Overlay
option.

Additionally, when multiple objects are selected, each object should
have its UV Wireframe drawn in the Image Editor. The selected objects
that aren't active should have less opaque wireframes to indicate which
wireframe belongs to the active object. This is the best approach for
having multiple objects selected since it allows the user to quickly
view the UV layout for all selected objects to troubleshoot UV problems,
like texture mapping. This is especially helpful when using a material
for multiple different objects.

An alternative solution would be to only show the UV Wireframe for the
active object, but this would be undesirable because it would make
troubleshooting UV positions tedious when working with multiple objects
since the user would need to select objects individually.

Co-authored-by: T0MIS0N <50230774+T0MIS0N@users.noreply.github.com>
Co-authored-by: Sean Kim <SeanCTKim@protonmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/135102
2025-04-04 21:30:05 +02:00
Hans Goudey
d3f84449ad Mesh: Add "free" custom normals
Add a "dumb vector" storage option for custom normals, with the
"custom_normal" attribute. Adjust the mesh normals caching to
provide this attribute if it's available, and add a geometry node to
store custom normals.

## Free Normals
They're called "free" in the sense that they're just direction vectors
in the object's local space, rather than the existing "smooth corner
fan space" storage. They're also "free" in that they make further
normals calculation very inexpensive, since we just use the custom
normals instead. That's a big improvement from the existing custom
normals storage, which usually significantly decreases
viewport performance. For example, in a simple test file just storing
the vertex normals on a UV sphere, using free normals gives 25 times
better playback performance and 10% lower memory usage.

Free normals are adjusted when applying a transformation to the entire
mesh or when realizing instances, but in general they're not updated for
vertex deformations.

## Set Mesh Normal Node
The new geometry node allows storing free custom normals as well as
the existing corner fan space normals. When free normals are chosen,
free normals can be stored on vertices, faces, or face corners. Using
the face corner domain is necessary to bake existing mixed sharp and
smooth edges into the custom normal vectors.

The node also has a mode for storing edge and mesh sharpness, meant
as a "soft" replacement to the "Set Shade Smooth" node that's a bit
more convenient.

## Normal Input Node
The normal node outputs free custom normals mixed to whatever domain is
requested. A "true normal" output that ignores custom normals and
sharpness is added as well.

Across Blender, custom normals are generally accessed via face and
vertex normals, when "true normals" are not requested explicitly.
In many cases that means they are mixed from the face corner domain.

## Future Work
1. There are many places where propagation of free normals could be
   improved. They should probably be normalized after mixing, and it
   may be useful to not just use 0 vectors for new elements. To keep
   the scope of this change smaller, that sort of thing generally isn't
   handled here. Searching `CD_NORMAL` gives a hint of where better
   propagation could be useful.
2. Free normals are displayed properly in edit mode, but the existing
   custom normal editing operators don't work with free normals yet.
   This will hopefully be fairly straightforward since custom normals
   are usually converted to `float3` for editing anyway. Edit mode
   changes aren't included here because they're unnecessary for the
   procedural custom normals use cases.
3. Most importers can probably switch to using free normals instead,
   or at least provide an option for it. That will give a significant
   import performance improvement, and an improvement of Blender's
   FPS for imported scenes too.

Pull Request: https://projects.blender.org/blender/blender/pulls/132583
2025-04-04 19:16:51 +02:00
Clément Foucault
6727675757 Fix: DRW: Shader printf not working inside draw context
The draw context was missing `GPU_render_begin/end`
calls which is where the printf buffer are created and
flushed.
2025-04-04 18:42:05 +02:00
Omar Emara
12ba9770db Fix #136699: Denoise node crash in viewport compositor
The Denoise node crashes if used in the viewport compositor. That's
because OIDN uses the compositor context in a different thread, which
does not have access to the DRW context. To fix this, we assign relevant
context data to the compositor context from the DRW context before
running the evaluator, then make the compositor context return those
data instead of accessing the DRW context.
2025-04-04 11:59:23 +02:00
Campbell Barton
4139d4a8f0 Cleanup: spelling in comments (make check_spelling_*) 2025-04-04 12:48:04 +11:00
Clément Foucault
d4d5136da0 Fix #136850: HDRI Preview Flickering in Viewport Shading
This was caused by the manager being in sync phase only
between `begin_sync` an `end_sync`. The drawcalls sync
inside `begin_sync` like the lookdev sphere were given
bogus handles.

This also remove some uneeded functions wrappers.
2025-04-03 19:35:51 +02:00
Clément Foucault
d7359c8164 Fix #136883: DRW: Crash with empty point cloud
This was caused by an emtpy VBO being bound as
a texture. This is undefined behavior on some implementation.
2025-04-03 18:53:22 +02:00
Clément Foucault
0fdbeba2c3 Fix #136911: Overlay: 3D Cursor disappears when opening File Open dialogue
One of the push constant was not set and was thus
in the last state is was in. This is because
we are not using the Batch or IMM API to draw
the batch, and thus, this push constant has to be
set manually upfront.
2025-04-03 17:28:09 +02:00
Clément Foucault
299a581b1b Grease Pencil: Accumulation Anti-aliasing
This adds a new more accurate antialiasing to the Grease Pencil
render engine. This is only available for render.

This Accumulation AA doesn't replace the SMAA. SMAA is still
used by the viewport and for removing aliasing from the
depth buffer. However, using both at the same time can lead
to overblurred result.

Here are some measurements for how much the render time
increases compared to the baseline with different (SSAA) sample
counts (using an example production file, rendered at 1080p,
results might vary depending on the scene complexity):
* 8 samples: +0.14 s
* 16 samples +0.36 s
* 32 samples: +0.58 s

Co-authored-by: Falk David <falk@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/136551
2025-04-03 16:52:05 +02:00
Clément Foucault
3064906eb7 Cleanup: GPU: Add ATTR_FALLTHROUGH for shader C++ compilation 2025-04-03 16:38:21 +02:00
Clément Foucault
f8de6c31bc EEVEE: Move Object ID storage to gbuffer header layer
This allow to store the full object ID inside a `uint32`
buffer. This allows to get the per object data in deferred
passes and avoid to store object data inside the Gbuffer.

This data is only written if needed.

This had to modify the implementation of subpass input
for all backend to be able to bind layered texture.
This currently work because only the layer 0 is bound to the
framebuffer. This is fragile but I don't see a good builtin way
to fix it.

Rel #135935

#### Tasks
- [x] Replace light linking bits in Gbuffer
- [x] Replace Object ID in GBuffer for SSS
- [x] Conditional storage
- [x] Dummy storage if not needed

Pull Request: https://projects.blender.org/blender/blender/pulls/136428
2025-04-03 14:00:55 +02:00
Miguel Pozo
1be036d883 Fix #136346: Workbench: Smoke simulation renders artifacts
Precent division by zero.
Unclear why this wasn't an issue before,
or why is not an issue outside OpenGL.
2025-04-02 17:03:34 +02:00
Campbell Barton
f89cf19ba6 Cleanup: indentation for CMake files, strip trailing space 2025-04-02 03:01:59 +00:00
Clément Foucault
9181485931 Fix #136235: Edit UV: Crash when modifying mesh in shaded viewport
This happened because the viewport was drawn after
the UV editor when some update occur (e.g. canceling an
operator). The requested UV edit batch would require only
one specific UV channel. The viewport, in need of a different
UV channel, requested a VBO rebuild (freing the old UV VBO)
but did not correctly clear the UV batches that were referencing
the said VBO. This lead to use after free which would sometime
works because the same memory would be reused for a random new
batch.

Pull Request: https://projects.blender.org/blender/blender/pulls/136780
2025-03-31 18:45:59 +02:00
Miguel Pozo
8f63f509b6 Fix #136501: Overlay: Edit Mode Edges occluded by viewport grid
Render Overlay Meshes after the Grid.
As a side effect, in-front wireframe objects are now displayed behind
non-in-front edit mode overlays.

Co-authored-by: Clément Foucault
Pull Request: https://projects.blender.org/blender/blender/pulls/136764
2025-03-31 17:37:00 +02:00
Jeroen Bakker
3ad5721a1c Fix #136767: SubDiv: Incorrect attribute interpolation
177bbf12df solved the out of bound read
by limiting the input search. However this lead to incorrect
interpolation. This has been fixed by moving the bound check as a
post check.

Pull Request: https://projects.blender.org/blender/blender/pulls/136769
2025-03-31 15:43:01 +02:00
Clément Foucault
cf0982d308 Cleanup: Grease Pencil: Merge Vfx methods into instance class
_No response_

Pull Request: https://projects.blender.org/blender/blender/pulls/136696
2025-03-31 10:33:29 +02:00
Campbell Barton
12e3a046a5 Cleanup: remove unused defines 2025-03-29 11:49:08 +11:00