GPv3: Envelope modifier implementation #118272

Merged
Falk David merged 36 commits from LukasTonne/blender:gp3-envelope-modifier into main 2024-03-01 10:42:53 +01:00
Member

Ports the Envelope modifier from GPv2.

TODO

  • Fix segments mode, the result does not look quite like GP2. Hard to tell what is going on in the code.
  • Support the Skip feature fully (only use every n-th point, might affect range of points in segments mode?)
  • Support Thickness and Strength factors.
Ports the _Envelope_ modifier from GPv2. ## TODO - [x] Fix segments mode, the result does not look quite like GP2. Hard to tell what is going on in the code. - [x] Support the _Skip_ feature fully (only use every n-th point, might affect range of points in segments mode?) - [x] Support _Thickness_ and _Strength_ factors.
Lukas Tönne added 21 commits 2024-02-14 14:18:41 +01:00
bc7e627b90 Attempt at implementing segments mode like GP2.
Doesn't quite look the same, it's hard to tell what the GPv2 modifier
actually does (and what it's supposed to do which are probably not the
same thing).
Lukas Tönne added this to the Grease Pencil project 2024-02-14 14:21:56 +01:00
Lukas Tönne added 1 commit 2024-02-17 10:14:20 +01:00
Author
Member

The GPv2 implementation of this modifier isn't well documented, so i took some time to try and understand what it does in detail, specifically for the generative Segments and Fills modes. The Deform mode is working as it is right now, even though the math is a little underexplained.

Expand wall of text

Segments mode

Lets start with a simple curve:
image

Segment mode creates simple 2-point lines between neighboring points. For a given spread S a line is created for every point pair (p-S+i, p+1+i). For example with a spread S=3 around point p the new lines would be [p-3, p+], [p-2, p+2], [p-1, p+3].
image

Most of these lines would be generated for neighboring points as well. In the example above, the line [p-2, p+2] would also be generated by the neighboring point p-1 as [(p-1)-1, (p-1)+3] and by point p+1 as [(p+1)-3, (p+1)+2]. Generally each point only needs to create one line, which drastically reduces the amount of redundant geometry.

One caveat (possibly a bug?) is that lines at the end points of a curve would stray into negative index territory, so the indices get clamped (for non-cyclic curves). The result is that multiple curves between the same points get generated. For example, around p=0 the generated lines
[-3, +1], [-2, +2], [-1, +3]
are clamped to
[0, 1], [0, 2], [0, 3]
which overlaps with lines by point p=1:
[0, 2], [0, 3], [0, 4].

These lines are not deduplicated, which is the reason the modifier generates "thicker" lines at the end points:
image

Fills mode

This mode is more mysterious/buggy. Instead of creating individual 2-point lines for every envelope pair, it creates a closed curve of surrounding points:
image

The way it uses the Spread setting is a bit weird: adding +1 to the spread alternatingly expands the neighborhood left or right, but not symmetrically:
image
image
image
image

The curves also have gaps at the end points, which are probably a bug too.
image

The segments mode may not end up working exactly the same in GPv3.

The GPv2 implementation of this modifier isn't well documented, so i took some time to try and understand what it does in detail, specifically for the generative _Segments_ and _Fills_ modes. The _Deform_ mode is working as it is right now, even though the math is a little underexplained. <details> <summary>Expand wall of text</summary> ## Segments mode Lets start with a simple curve: ![image](/attachments/df720eb9-c0da-48d5-9746-f5199454752f) Segment mode creates simple 2-point lines between neighboring points. For a given spread `S` a line is created for every point pair `(p-S+i, p+1+i)`. For example with a spread `S=3` around point `p` the new lines would be `[p-3, p+]`, `[p-2, p+2]`, `[p-1, p+3]`. ![image](/attachments/b7e8befe-0883-433a-976a-a8b7a4200314) Most of these lines would be generated for neighboring points as well. In the example above, the line `[p-2, p+2]` would also be generated by the neighboring point `p-1` as `[(p-1)-1, (p-1)+3]` and by point `p+1` as `[(p+1)-3, (p+1)+2]`. Generally each point only needs to create one line, which drastically reduces the amount of redundant geometry. One caveat (possibly a bug?) is that lines at the end points of a curve would stray into negative index territory, so the indices get clamped (for non-cyclic curves). The result is that multiple curves between the same points get generated. For example, around `p=0` the generated lines `[-3, +1]`, `[-2, +2]`, `[-1, +3]` are clamped to `[0, 1]`, `[0, 2]`, `[0, 3]` which overlaps with lines by point `p=1`: `[0, 2]`, `[0, 3]`, `[0, 4]`. These lines are not deduplicated, which is the reason the modifier generates "thicker" lines at the end points: ![image](/attachments/1d2b1192-bd2c-4c23-b41b-69f5a30c7856) ## Fills mode This mode is more mysterious/buggy. Instead of creating individual 2-point lines for every envelope pair, it creates a closed curve of surrounding points: ![image](/attachments/5b0f0ecd-30a7-4954-9bf9-66876cd13c82) The way it uses the _Spread_ setting is a bit weird: adding +1 to the spread alternatingly expands the neighborhood left or right, but not symmetrically: ![image](/attachments/cab4dddc-7b14-4645-adba-c4fd4195abff) ![image](/attachments/20337a91-69bc-416a-bce0-9a878857569a) ![image](/attachments/46ec06b4-30ab-4e28-9072-8575202fe391) ![image](/attachments/11247499-b8ea-446f-9819-8707da8784e4) The curves also have gaps at the end points, which are probably a bug too. ![image](/attachments/5972a646-5a4d-4e36-897a-bf40743cdedf) The segments mode may not end up working exactly the same in GPv3. </details>
Contributor

Maybe @weasel as the author of the current modifier can help (https://archive.blender.org/developer/D14341).

Maybe @weasel as the author of the current modifier can help (https://archive.blender.org/developer/D14341).
Lukas Tönne added 1 commit 2024-02-19 11:52:02 +01:00
Lukas Tönne added 1 commit 2024-02-19 14:55:55 +01:00
Lukas Tönne added 2 commits 2024-02-19 15:22:20 +01:00
Lukas Tönne added 2 commits 2024-02-19 15:56:24 +01:00
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
f8da9073c8
CLeanup: remove debug prints.
Lukas Tönne changed title from WIP: GPv3: Envelope modifier implementation to GPv3: Envelope modifier implementation 2024-02-19 15:56:31 +01:00
Author
Member

@blender-bot build

@blender-bot build
Lukas Tönne requested review from Falk David 2024-02-19 17:36:53 +01:00
Lukas Tönne requested review from Henrik D. 2024-02-19 17:37:03 +01:00
Falk David requested changes 2024-02-20 11:49:41 +01:00
Falk David left a comment
Member

Overall this looks good. Just a have a small cleanup comment.

Overall this looks good. Just a have a small cleanup comment.
@ -0,0 +118,4 @@
const float diff_dir = p1_dir - p2_dir;
float u;
if (diff_dir != 0.0f) {
Member

Maybe this could be a function? So that we can do:

const float u = calculate_u(...);

or as a lambda

const float u = [&]() {
   ...
}();
Maybe this could be a function? So that we can do: ``` const float u = calculate_u(...); ``` or as a lambda ``` const float u = [&]() { ... }(); ```
LukasTonne marked this conversation as resolved
Lukas Tönne added 2 commits 2024-02-21 12:05:46 +01:00
Falk David approved these changes 2024-02-21 12:17:07 +01:00
Falk David left a comment
Member

Will let @weasel check the math, but overall this looks good to me.

Will let @weasel check the math, but overall this looks good to me.
Lukas Tönne added 1 commit 2024-02-26 12:49:11 +01:00
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
e73be9a3af
Merge branch 'main' into gp3-envelope-modifier
Author
Member

@blender-bot build

@blender-bot build
Iliya Katushenock reviewed 2024-02-26 12:51:47 +01:00
@ -0,0 +446,4 @@
const bool src_curve_cyclic,
const VArray<int> &src_material_indices,
const IndexRange dst_points,
const MutableSpan<int> curve_offsets,

const MutableSpan<int> curve_offsets -> MutableSpan<int> curve_offsets
There is no point in having a constant if the values themselves will change.

`const MutableSpan<int> curve_offsets` -> `MutableSpan<int> curve_offsets` There is no point in having a constant if the values themselves will change.
Author
Member

Oh? I've used this a lot before, pretty sure Hans wanted it this way in other reviews. The values are still mutable when the span itself is const. It's unlikely that anyone would accidentally change the span instead of accessing elements of it, but making it const can't hurt.

Oh? I've used this a lot before, pretty sure Hans wanted it this way in other reviews. The values are still mutable when the span itself is const. It's unlikely that anyone would accidentally change the span instead of accessing elements of it, but making it const can't hurt.

It took me a lot of thinking just to realize that this was data to be changed. I see a bunch of constants in parameters, and the void result, and my first thought is: what does this function even do?

It took me a lot of thinking just to realize that this was data to be changed. I see a bunch of constants in parameters, and the void result, and my first thought is: what does this function even do?
@HooglyBoogly /
Member

To me the more important is: https://developer.blender.org/docs/handbook/guidelines/c_cpp/#return-arguments since this is basically "returning" the result in these mutable spans.
So these should be named r_curve_offsets, etc. const or no const. That will make it clear.

To me the more important is: https://developer.blender.org/docs/handbook/guidelines/c_cpp/#return-arguments since this is basically "returning" the result in these mutable spans. So these should be named `r_curve_offsets`, etc. `const` or no `const`. That will make it clear.
Member

Personally I don't use const in cases like this since visually it looks more separate. So I don't think I would have asked for it. But I think it's a very reasonable choice, and being more "strict" about const makes sense too! I don't really think a mutable span argument always needs a r_ prefix, it's often not helpful.

Personally I don't use `const` in cases like this since visually it looks more separate. So I don't think I would have asked for it. But I think it's a very reasonable choice, and being more "strict" about const makes sense too! I don't really think a mutable span argument always needs a `r_` prefix, it's often not helpful.
Lukas Tönne added 1 commit 2024-02-26 16:58:59 +01:00
buildbot/vexp-code-patch-lint 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-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
27047acedb
Merge branch 'main' into gp3-envelope-modifier
Author
Member

@blender-bot build

@blender-bot build
Member

Testing this, it seems to work exactly like the old code, except for the discussed bugfix on the end of fills. However I found a bug in the old version which is still there. Imo it is a bug, that in case the spread is higher than the length of the stroke, it keeps duplicating the end to end stroke. For non cyclic strokes, the spread should be clamped to point_count-2 imo, such that the end to end stroke is never duplicated.

Looking at the code I found no math errors. Just a minor performance regression in a weird special case.

Testing this, it seems to work exactly like the old code, except for the discussed bugfix on the end of fills. However I found a bug in the old version which is still there. Imo it is a bug, that in case the spread is higher than the length of the stroke, it keeps duplicating the end to end stroke. For non cyclic strokes, the spread should be clamped to `point_count-2` imo, such that the end to end stroke is never duplicated. Looking at the code I found no math errors. Just a minor performance regression in a weird special case.
Henrik D. requested changes 2024-02-26 23:56:41 +01:00
@ -0,0 +180,4 @@
if (point == 0 || point >= point_num - 1) {
return unlimited_radius;
}
for (const int line_i : IndexRange(spread)) {
Member

This loop is longer than in the original. Afaict it checks the same point multiple times at the boundaries, which does work, but is unecessary.

This loop is longer than in the original. Afaict it checks the same point multiple times at the boundaries, which does work, but is unecessary.
Author
Member

Clamping to relevant point spread now.

Clamping to relevant point spread now.
LukasTonne marked this conversation as resolved
Lukas Tönne added 1 commit 2024-02-27 09:58:06 +01:00
Lukas Tönne added 1 commit 2024-02-27 10:35:13 +01:00
Lukas Tönne added 1 commit 2024-02-27 10:44:29 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
d8f361c792
GPv2 conversion code for the envelope modifier.
Author
Member

@blender-bot build

@blender-bot build
Falk David requested review from Henrik D. 2024-02-27 11:31:54 +01:00
Lukas Tönne added 1 commit 2024-03-01 10:19:13 +01:00
Falk David merged commit 68c12fe0ec into main 2024-03-01 10:42:53 +01:00
Falk David referenced this issue from a commit 2024-03-01 10:42:54 +01:00
Lukas Tönne deleted branch gp3-envelope-modifier 2024-03-01 10:56:22 +01:00
Sign in to join this conversation.
No reviewers
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 project
No Assignees
6 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#118272
No description provided.