Curves: Add basic custom normals support #116066

Merged
Hans Goudey merged 20 commits from HooglyBoogly/blender:curves-normals into main 2023-12-21 03:29:28 +01:00
Member

Add a new normal mode called "Custom" which directly interpolates
a "custom_normal" attribute to the evaluated points for the final
normal. Extend the "Set Curve Normal" node with this mode and
give it the ability to set the custom normal value.

This is intentionally a very basic implementation of custom normals.
In particular, the storage is not rotation invariant. So the normals
are expected to be set procedurally at the end of the modifier stack.
On the other hand, it is very easy to understand and explain.

Note that custom normals are not stored per Bezier handle.
This is a general problem with Blender's Bezier curve design.


Screenshot from 2023-12-11 17-26-07

Add a new normal mode called "Custom" which directly interpolates a "custom_normal" attribute to the evaluated points for the final normal. Extend the "Set Curve Normal" node with this mode and give it the ability to set the custom normal value. This is intentionally a very basic implementation of custom normals. In particular, the storage is not rotation invariant. So the normals are expected to be set procedurally at the end of the modifier stack. On the other hand, it is very easy to understand and explain. Note that custom normals are not stored per Bezier handle. This is a general problem with Blender's Bezier curve design. --- ![Screenshot from 2023-12-11 17-26-07](/attachments/ad900d77-c6e5-462f-8d73-b7b441c63d32)
Hans Goudey added 5 commits 2023-12-11 23:27:53 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
8fb251afd9
Finish
Author
Member

@blender-bot package

@blender-bot package
Member

Package build started. Download here when ready.

Package build started. [Download here](https://builder.blender.org/download/patch/PR116066) when ready.
Hans Goudey requested review from Simon Thommes 2023-12-11 23:37:15 +01:00
Hans Goudey requested review from Jacques Lucke 2023-12-11 23:37:21 +01:00
Hans Goudey added this to the Nodes & Physics project 2023-12-11 23:37:27 +01:00
Hans Goudey added this to the 4.1 milestone 2023-12-11 23:37:30 +01:00
Hans Goudey added the
Module
Nodes & Physics
Interest
Geometry Nodes
Interest
Modeling
labels 2023-12-11 23:37:44 +01:00
Hans Goudey added 1 commit 2023-12-11 23:39:16 +01:00
Simon Thommes approved these changes 2023-12-15 10:50:38 +01:00
Simon Thommes left a comment
Member

This simple approach already brings a lot of control that is currently not possible to achieve and even once a more 'smart' approach will exist that can be relative to some space per curve, this approach is still useful to override the normals in local object space.

We talked about the name of this option and changing it to something like Free. I'm not too opinionated on this tbh. Might be interesting to think about how other modes in the future would be called, but I think we could still change the name then to make it fit better into the context of those other modes.

This simple approach already brings a lot of control that is currently not possible to achieve and even once a more 'smart' approach will exist that can be relative to some space per curve, this approach is still useful to override the normals in local object space. We talked about the name of this option and changing it to something like `Free`. I'm not too opinionated on this tbh. Might be interesting to think about how other modes in the future would be called, but I think we could still change the name then to make it fit better into the context of those other modes.
Member

Generally seems ok, but I still have concerns.

  • I prefer Free over Custom as well.
  • It feels kinda bad that the normal isn't even updated by the Transform Geometry and Realize Instances nodes... Setting custom normals feels much more limited if those two nodes can break them already. If we wanted to add that later, we will have to add this as an option because otherwise it would break backward compatibility. How could one keep normals intact after a realizing instances now with just this patch?
  • I think previously it was guaranteed that CurvesGeometry::evaluated_tangents() and CurvesGeometry::evaluated_normals() are orthogonal. This is not the case anymore. If this is not fixed, it should at least to explicitly documented. Also I'd like to see some good use case that justifies calling those vectors "normals", instead of just using them as normal attributes. Looks like the Curve to Mesh node is the only node using the evaluated normals as input currently. In theory we could also just expose a normal input in that node instead.
Generally seems ok, but I still have concerns. * I prefer `Free` over `Custom` as well. * It feels kinda bad that the normal isn't even updated by the `Transform Geometry` and `Realize Instances` nodes... Setting custom normals feels much more limited if those two nodes can break them already. If we wanted to add that later, we will have to add this as an option because otherwise it would break backward compatibility. How could one keep normals intact after a realizing instances now with just this patch? * I think previously it was guaranteed that `CurvesGeometry::evaluated_tangents()` and `CurvesGeometry::evaluated_normals()` are orthogonal. This is not the case anymore. If this is not fixed, it should at least to explicitly documented. Also I'd like to see some good use case that justifies calling those vectors "normals", instead of just using them as normal attributes. Looks like the `Curve to Mesh` node is the only node using the evaluated normals as input currently. In theory we could also just expose a normal input in that node instead.
Hans Goudey added 1 commit 2023-12-18 15:55:14 +01:00
Hans Goudey added 4 commits 2023-12-18 16:33:15 +01:00
Author
Member
  • I prefer Free over Custom as well.

Right, changed that now. The attribute is still called custom_normal though. Don't have a strong opinion, but I guess that represents its goal the best.

  • It feels kinda bad that the normal isn't even updated by the Transform Geometry and Realize Instances nodes...

Great point, added that now.

  • I think previously it was guaranteed that CurvesGeometry::evaluated_tangents() and CurvesGeometry::evaluated_normals() are orthogonal. This is not the case anymore. If this is not fixed, it should at least to explicitly documented.

Yes, I will document this.

Also I'd like to see some good use case that justifies calling those vectors "normals", instead of just using them as normal attributes. Looks like the Curve to Mesh node is the only node using the evaluated normals as input currently. In theory we could also just expose a normal input in that node instead.

Unfortunately it's not that simple. Evaluating a field on control points and interpolating it to evaluated points wouldn't give the same behavior for all curve types, especially Bezier curves where the handles can't store attributes. Normals are calculated based on evaluated points positions in general too. Theoretically there could be a special case for the "Normal" input, but without a more general abstraction for operating on evaluated points with fields, I think that's just too magical.

> * I prefer `Free` over `Custom` as well. Right, changed that now. The attribute is still called `custom_normal` though. Don't have a strong opinion, but I guess that represents its goal the best. > * It feels kinda bad that the normal isn't even updated by the `Transform Geometry` and `Realize Instances` nodes... Great point, added that now. > * I think previously it was guaranteed that `CurvesGeometry::evaluated_tangents()` and `CurvesGeometry::evaluated_normals()` are orthogonal. This is not the case anymore. If this is not fixed, it should at least to explicitly documented. Yes, I will document this. > Also I'd like to see some good use case that justifies calling those vectors "normals", instead of just using them as normal attributes. Looks like the `Curve to Mesh` node is the only node using the evaluated normals as input currently. In theory we could also just expose a normal input in that node instead. Unfortunately it's not that simple. Evaluating a field on control points and interpolating it to evaluated points wouldn't give the same behavior for all curve types, especially Bezier curves where the handles can't store attributes. Normals are calculated based on evaluated points positions in general too. Theoretically there could be a special case for the "Normal" input, but without a more general abstraction for operating on evaluated points with fields, I think that's just too magical.
Jacques Lucke requested changes 2023-12-19 00:41:10 +01:00
@ -160,2 +160,4 @@
*/
Span<float> nurbs_weight;
Span<float3> custom_normal;
Member

Could use a comment explaining why it has special handling.

Could use a comment explaining why it has special handling.
HooglyBoogly marked this conversation as resolved
@ -1359,1 +1380,4 @@
if (all_curves_info.create_custom_normal_attribute) {
if (curves_info.custom_normal.is_empty()) {
all_handle_right.slice(dst_point_range).fill(float3(0, 0, 1));
Member

Copy paste error (all_handle_right).

Copy paste error (`all_handle_right`).
HooglyBoogly marked this conversation as resolved
@ -1360,0 +1383,4 @@
all_handle_right.slice(dst_point_range).fill(float3(0, 0, 1));
}
else {
copy_transformed_directions(
Member

Seems correct, but I was wondering whether this needs similar treatment as when deforming mesh normals which are multiplied with transpose of the inverse of that matrix. Maybe you can double check that: https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/geometry/transforming-normals.html

Seems correct, but I was wondering whether this needs similar treatment as when deforming mesh normals which are multiplied with transpose of the inverse of that matrix. Maybe you can double check that: https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/geometry/transforming-normals.html
Author
Member

Ah, I guess I thought transform_direction was a solution to that, but looking into it more I'm not sure. I'll research this more.

Ah, I guess I thought `transform_direction` was a solution to that, but looking into it more I'm not sure. I'll research this more.
HooglyBoogly marked this conversation as resolved
@ -23,1 +23,4 @@
b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
if (const bNode *node = b.node_or_null()) {
if (node->custom1 == NORMAL_MODE_CUSTOM) {
b.add_input<decl::Vector>("Normal").default_value({0.0f, 0.0f, 1.0f}).field_on_all();
Member

For this kind of socket we don't use dynamic socket declarations yet, because it's incompatible with the idea of exposing the enum as socket.

For this kind of socket we don't use dynamic socket declarations yet, because it's incompatible with the idea of exposing the enum as socket.
Author
Member

Right, good point

Right, good point
HooglyBoogly marked this conversation as resolved
Hans Goudey added 1 commit 2023-12-19 16:01:56 +01:00
Hans Goudey added 4 commits 2023-12-19 16:48:49 +01:00
Hans Goudey requested review from Jacques Lucke 2023-12-19 16:48:59 +01:00
Jacques Lucke approved these changes 2023-12-20 00:21:32 +01:00
@ -1057,6 +1078,16 @@ static void transform_positions(MutableSpan<float3> positions, const float4x4 &m
});
}
static void transform_directions(MutableSpan<float3> directions, const float4x4 &matrix)
Member

same as in the other transform normal function in realize_instances.cc.

same as in the other transform normal function in `realize_instances.cc`.
HooglyBoogly marked this conversation as resolved
@ -293,6 +298,23 @@ static void copy_transformed_positions(const Span<float3> src,
});
}
static void copy_transformed_directions(const Span<float3> src,
Member

copy_transformed_normals

`copy_transformed_normals`
HooglyBoogly marked this conversation as resolved
@ -296,0 +309,4 @@
else {
threading::parallel_for(src.index_range(), 1024, [&](const IndexRange range) {
for (const int i : range) {
dst[i] = math::transform_direction(normal_transform, src[i]);
Member

Might be reasonable to use raw matrix multiplication here, since you did the direction-specific part already above and ended up with a 3x3 matrix.

Might be reasonable to use raw matrix multiplication here, since you did the direction-specific part already above and ended up with a 3x3 matrix.
HooglyBoogly marked this conversation as resolved
Hans Goudey added 4 commits 2023-12-21 03:20:08 +01:00
Hans Goudey merged commit f63a7c1ee9 into main 2023-12-21 03:29:28 +01:00
Hans Goudey deleted branch curves-normals 2023-12-21 03:29:30 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#116066
No description provided.