GPv3: Add Catmull-Clark option in subdivide modifier #117382

Merged
Falk David merged 3 commits from ChengduLittleA/blender:gp3-mod-subdiv-smooth into main 2024-01-24 13:14:16 +01:00
Member

The subdivide modifier of Grease Pencil v3 was lacking catmull smoothing option when it
was merged at first due to no apparent API for doing that directly. Now re-implemented
using CURVE_TYPE_CATMULL_ROM and curves.evaluated_positions().

The subdivide modifier of Grease Pencil v3 was lacking catmull smoothing option when it was merged at first due to no apparent API for doing that directly. Now re-implemented using `CURVE_TYPE_CATMULL_ROM` and `curves.evaluated_positions()`.
YimingWu added the
Module
Grease Pencil
label 2024-01-21 14:35:32 +01:00
YimingWu added 1 commit 2024-01-21 14:35:44 +01:00
Falk David added this to the Grease Pencil project 2024-01-22 12:56:18 +01:00
Member

@ChengduLittleA Unfortunately, this does not seem to work like in GPv2 :/ I'll think about this some more.

@ChengduLittleA Unfortunately, this does not seem to work like in GPv2 :/ I'll think about this some more.
Member

This is a direct port of the old implementation, but it has some issues

if (use_catmull_clark) {
  bke::CurvesGeometry subdivided_curves = drawing.strokes();
  for ([[maybe_unused]] const int level_i : IndexRange(mmd.level)) {
    VArray<int> one_cut = VArray<int>::ForSingle(1, subdivided_curves.points_num());
    subdivided_curves = geometry::subdivide_curves(
        subdivided_curves, strokes, std::move(one_cut), {});

    offset_indices::OffsetIndices<int> points_by_curve = subdivided_curves.points_by_curve();
    MutableSpan<float3> positions = subdivided_curves.positions_for_write();
    threading::parallel_for(subdivided_curves.curves_range(), 1024, [&](const IndexRange range) {
      for (const int curve_i : range) {
        const IndexRange points = points_by_curve[curve_i];
        for (const int point_i : points.drop_front(1).drop_back(1)) {
          positions[point_i] = math::interpolate(
              positions[point_i],
              math::interpolate(positions[point_i - 1], positions[point_i + 1], 0.5f),
              0.5f);
        }
      }
    });
  }
  drawing.strokes_for_write() = subdivided_curves;
}
else {
  VArray<int> cuts = VArray<int>::ForSingle(mmd.level, drawing.strokes().points_num());
  drawing.strokes_for_write() = geometry::subdivide_curves(
      drawing.strokes(), strokes, std::move(cuts), {});
}
  1. It means that mmd.level is treated as a power of 2 again so anything higher than 5 gets very slow.
  2. It's an iterative algorithm that has to subidivide once per iteration.

We could add a seperate level input for the Catmull-Clark mode and change the limits for it, but that doesn't seem like the best idea.

@HooglyBoogly Anything you can think of maybe? I'm not sure if there is a good way to compute the "final" catmull-clark positions. That would be ideal because then we can just do the normal geometry::subdivide_curves and call something like geometry::smooth_curves_catmull_clark after.

This is a direct port of the old implementation, but it has some issues ```cpp if (use_catmull_clark) { bke::CurvesGeometry subdivided_curves = drawing.strokes(); for ([[maybe_unused]] const int level_i : IndexRange(mmd.level)) { VArray<int> one_cut = VArray<int>::ForSingle(1, subdivided_curves.points_num()); subdivided_curves = geometry::subdivide_curves( subdivided_curves, strokes, std::move(one_cut), {}); offset_indices::OffsetIndices<int> points_by_curve = subdivided_curves.points_by_curve(); MutableSpan<float3> positions = subdivided_curves.positions_for_write(); threading::parallel_for(subdivided_curves.curves_range(), 1024, [&](const IndexRange range) { for (const int curve_i : range) { const IndexRange points = points_by_curve[curve_i]; for (const int point_i : points.drop_front(1).drop_back(1)) { positions[point_i] = math::interpolate( positions[point_i], math::interpolate(positions[point_i - 1], positions[point_i + 1], 0.5f), 0.5f); } } }); } drawing.strokes_for_write() = subdivided_curves; } else { VArray<int> cuts = VArray<int>::ForSingle(mmd.level, drawing.strokes().points_num()); drawing.strokes_for_write() = geometry::subdivide_curves( drawing.strokes(), strokes, std::move(cuts), {}); } ``` 1. It means that `mmd.level` is treated as a power of 2 again so anything higher than 5 gets very slow. 2. It's an iterative algorithm that has to subidivide once per iteration. We could add a seperate `level` input for the `Catmull-Clark` mode and change the limits for it, but that doesn't seem like the best idea. @HooglyBoogly Anything you can think of maybe? I'm not sure if there is a good way to compute the "final" catmull-clark positions. That would be ideal because then we can just do the normal `geometry::subdivide_curves` and call something like `geometry::smooth_curves_catmull_clark` after.
Author
Member

I think it would be hard to use the linear level for Catmull-Clark, since to do that perfectly you'll then need to have a "limit curve" and sample the points along it, like in OpenSubdiv you can get a limit surface without actually having to subdivide the geometry.

I think it would be hard to use the linear `level` for Catmull-Clark, since to do that perfectly you'll then need to have a "limit curve" and sample the points along it, like in OpenSubdiv you can get a limit surface without actually having to subdivide the geometry.
Member

I would recommend just porting the old modifier's logic. It seems important to frame our efforts with the modifiers in the right context. The main goal of adding the modifiers is compatibility. If we get better performance that's nice, but long term these things should be implemented with nodes anyway. So I'd suggest not overthinking this and just doing the simplest thing.

I would recommend just porting the old modifier's logic. It seems important to frame our efforts with the modifiers in the right context. The main goal of adding the modifiers is compatibility. If we get better performance that's nice, but long term these things should be implemented with nodes anyway. So I'd suggest not overthinking this and just doing the simplest thing.
Author
Member

@filedescriptor does the "direct port" of the algorithm work exactly the same way as the old one? If so I think we could use 3 modes: Simple, Subdiv Smooth (the linear subdiv mode that's current, with mid-point smooth), and Catmull-Clark (for the old behaviour). Thoughts?

@filedescriptor does the "direct port" of the algorithm work exactly the same way as the old one? If so I think we could use 3 modes: `Simple`, `Subdiv Smooth` (the linear subdiv mode that's current, with mid-point smooth), and `Catmull-Clark` (for the old behaviour). Thoughts?
Iliya Katushenock reviewed 2024-01-24 09:32:58 +01:00
@ -90,2 +97,4 @@
/* Simple subdiv first, then we can catmull smooth positions. */
drawing.strokes_for_write() = geometry::subdivide_curves(
drawing.strokes(), strokes, std::move(cuts), {});

Argument cuts is taken by const reference, you can delete std::move and back const to variable declaration.

Argument `cuts` is taken by const reference, you can delete `std::move` and back `const` to variable declaration.
ChengduLittleA marked this conversation as resolved
Member

@ChengduLittleA Yes, the code above will give the same results as the old one.

I'm not sure what you mean with Subdiv Smooth. Seems like that would be the same thing as Catmull-Clark.

I think we should stick to having the two modes as before Simple and Catmull-Clark. But because Catmull-Clark subdivides exponetially, we have to do the same in the Simple mode. Basically restoring the old behavior exactly.

So to summarize:

  • Add the code path for Catmull-Clark.
  • Use math::pow(2, mmd.level) for geometry::subdivide_curves in Simple mode.
  • Restore the old limits in RNA
@ChengduLittleA Yes, the code above will give the same results as the old one. I'm not sure what you mean with `Subdiv Smooth`. Seems like that would be the same thing as `Catmull-Clark`. I think we should stick to having the two modes as before `Simple` and `Catmull-Clark`. But because `Catmull-Clark` subdivides exponetially, we have to do the same in the `Simple` mode. Basically restoring the old behavior exactly. So to summarize: * Add the code path for `Catmull-Clark`. * Use `math::pow(2, mmd.level)` for `geometry::subdivide_curves` in `Simple` mode. * Restore the old limits in RNA
YimingWu added 1 commit 2024-01-24 11:48:25 +01:00
Falk David approved these changes 2024-01-24 11:57:12 +01:00
Falk David left a comment
Member

Thanks for updating. Just one cleanup comment.

Thanks for updating. Just one cleanup comment.
@ -7766,6 +7766,12 @@ static void rna_def_modifier_grease_pencil_subdiv(BlenderRNA *brna)
StructRNA *srna;
PropertyRNA *prop;
static const EnumPropertyItem gpencil_subdivision_type_items[] = {
Member

Can just be subdivision_type_items

Can just be `subdivision_type_items`
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2024-01-24 12:34:56 +01:00
Falk David changed title from GPv3: Catmull smoothing in Subdiv modifier to GPv3: Add Catmull-Clark option in subdivide modifier 2024-01-24 13:11:36 +01:00
Falk David merged commit 756f7cf1e8 into main 2024-01-24 13:14:16 +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
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#117382
No description provided.