Grease Pencil Integration into Geometry Nodes

In the past week, the geometry nodes team, technical artists from the Blender Studio, as well as myself came together to come up with an initial design for the Grease Pencil integration into Geometry Nodes that would be ready for main (behind the “Grease Pencil 3” experimental flag). In this post, I’d like to describe what we have agreed upon.

Principle

In the context of Geometry Nodes, Grease Pencil is just a bunch of Curves. All the nodes that work for Curves should also work for Grease Pencil.

The Grease Pencil Geometry Component

Grease Pencil will be exposed as its own Geometry Component. First, let’s remind ourselves how Grease Pencil data is structured.

The Grease Pencil data contains a list of grease pencil layers**. Each layer has its own “timeline” where keyframes represent a drawing. We can think of a drawing as just Curves geometry.
One powerful aspect of grease pencil is that each keyframe can have its own geometry. This enables the frame-by-frame workflow that 2D animators are used to.
In the context of modifiers and geometry nodes, each layer will “contain” one Curves geometry - the one that is visible on the current frame.


Screenshot of the grease pencil dopesheet. The highlighted keyframes are the visible ones. Each of them refers to its own Curves geometry.

Layer Domain

Layers can have custom attributes. The Grease Pencil component will have a Layer domain:


Work-in-progress spreadsheet domains UI

Importantly, Grease Pencil geometry does not have a curve or point domain. This is because each layer contains its own Curves geometry, separate from all the other ones. Therefor each layer can have different attributes on their curve and point domain. This is similar to how Instances work, with the difference that layers cannot be nested. There is just a flat list of them in the Grease Pencil geometry.

**Technically the layers are structured in a tree where layer groups are nodes that can have zero or more layer nodes as children. This does not matter for geometry nodes though, because layer groups cannot have attributes and are meant for visual organization. In the context of geometry nodes, we treat layers as being in a flat list.

Field Evaluation Design

As described above, there is no curve/point domain on the Grease Pencil geometry. This has the important consequence that we cannot adapt the layer domain to, say, the curve domain.

However, we can still evaluate fields on the curve/point domain by iterating over all layers and evaluating the field on each Curves geometry separately.

This means that e.g. when using the Index input for a node that works on the point domain it will evaluate this field individually across all layers rather than globally.
For example, if there are 2 layers, one with 10 points and one with 15 points, a node evaluating a field that uses the Index input will evaluate for the first layer (index ranges from [0,9]) and for the second (index ranges from [0,14]), rather than evaluating across all layers with indices ranging from [0,24].

First Milestone

For the first milestone, the plan is to first add the layer domain and allow layers to have custom attributes. Then the idea is to not add any new nodes. Instead, we’ll make existing nodes work with Grease Pencil geometry. Namely all the Curves nodes.

So the first milestone should include:

  • Attribute nodes
    • E.g. storing/reading named attributes.
  • Generic geometry nodes
    • E.g. “Transform”, “Set Position”, etc.
  • Curve nodes
    • E.g. “Trim Curve”
  • Material nodes
    • E.g. “Set Material”

Example

Here we have an example of how Grease Pencil would behave in Geometry Nodes.
The Grease Pencil object has two layers. “Lines” and “GP_Layer”. The latter is hidden.
The two layers show up in the spreadsheet as two rows (0 and 1). Storing a named attribute on the layer domain shows up as a column as you would expect.

The “Set Position” node sets the position of the points of the Curves geometry in each layer. Here we’re using a noise texture to add some noise to the drawing.

The “Trim Curve” node trims all the curves in all the layers. In this case we just trim all of them by a fixed value from the start and end.

Pull Request

Of course this is still WIP, but the PR with the current state can be found here: #112535 - WIP: GPv3: Geometry Nodes - blender - Blender Projects

Get Involved

If you’d like to contribute to the Grease Pencil 3 project, head on over to the chat. It’s always good to ask in there if there is anything to be worked on. We also have a workboard with todo tasks and community tasks for new contributors.

26 Likes

Is it possible that to have in Spreadsheet, under Layer domain, two nested domains for Points and Lines, that display number of points and lines you have based on where you’re in the timeline, and what drawings are showing at that time?

And their attributes are shown also based on what’s shown. For example if you do Geometry Proximity and store distance as attribute on Lines domain, spreadsheet displays attribute for each index on each frame.

This might be stupid I’m just saying what comes to mind. I am just not understanding how selections based on some attribute will happen. In this example, I want to thicken lines on layer 0 based on geometry proximity. If I store the attribute to that index, will it work as expected, but without displaying attribute for each point in Spreadsheet?

Showing the total number of points and curves inside a grease pencil geometry is technically possible, but I wouldn’t want to show them in the spreadsheet as domains, because that would give a wrong impression. There is no point or curve domain on the grease pencil geometry.

For your example with the geometry proximity, what you would want to do is a selection based on a layer. That would give you Curves geometry to work with and you’d be able to see the attributes in the spreadsheet under the CurvesPoints/Spline domains.

3 Likes

Is this about GP having its own geometry nodes modifier implementation or being able to use GP in any arbitrary geometry nodes setup in other objects?

Gpencil: its own GN actually

1 Like

Hmm that is still great. I am also wondering if we would be able to process GP in other object gn networks.

When will we see a build of this for testing?

This is a very exciting to see! I can also envisage this being very useful for 2d mograph. Are there future plans to also get access to fill materials and data via geonodes as well as layer properties?

No, there is nothing different about these geo nodes setup from any other object. And yes you’d be able to use them with other objects.

3 Likes

That’s not right. Where did you get that from?

sorry poor english as you mentioned like every other object,

This is going to be one of the most amazing and unique things about Blender. Thanks for implementing it.

1 Like

how can we access layer names? why not to make attributes for layers based on layer’s path? it should cover nested path even if layers inside a group

2 Likes

that might be to much work, i don’t think any other domain has named elements, and the it would mean dadding a new node

but maybe a layer’s attribute could expose it’s name and its parent’s id? that way for now we could simply filter the layer by comparing the name attr with a string?

it’s dirty but it works, and eventually when adding new nodes a “get grease pencil layer by name” or something could be implemented

Selection of layers will likely come at a later stage. The idea is to not have selection based on names at first, but rather an input from the modifier panel where you’d be able to select a layer or a layer group from a drop down. This would then give you a selection field in the group input.
Later we could have a node that would work based on names. Similar to the “Material Selection” node for example. And then that would also show up in the “Internal Dependencies” section in the modifier.

7 Likes

Update: The main part of this design already landed in main and should be available in the daily builds: GPv3: Initial Geometry Nodes support

For now, the Set Position plus some other attribute nodes are working. More nodes will be supported soon.

12 Likes

Nice!

Is the node tools support considered too?

8 Likes

It’s not a target for now, but I’m sure it will come eventually.

4 Likes

It is not in fba58a148317 (oct12 build) Is this going to be in soon? Is there a sample video/scene that shows how to use it?

This is already in the 4.1 builds, not sure what you mean? I don’t know if there will be a video since it’s all still experimental.