Skip to content

Add mesh gradient support - #4081

Open
YohYamasaki wants to merge 21 commits into
GraphiteEditor:masterfrom
YohYamasaki:mesh-gradient-poc
Open

Add mesh gradient support#4081
YohYamasaki wants to merge 21 commits into
GraphiteEditor:masterfrom
YohYamasaki:mesh-gradient-poc

Conversation

@YohYamasaki

@YohYamasaki YohYamasaki commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Closes #3990

Screen.Recording.2026-08-17.at.13.03.19.mp4

Add the Coons patch-based mesh gradient paint.

Neither the current SVG specification nor Vello natively supports mesh gradient rendering, so the current implementations approximate mesh gradient behavior using linear gradients and alpha masks.
A Coons patch's shape is defined by its Bézier outlines. For SVG, it is replicated by feDisplacementMap, and approximated subdividing into multiple parallelograms for Vello. This ensures that the original shape, before transformation, can be a rectangle with affine transformation. Then, the color in the rectangle is blended bi-linearly or bi-cubically depending on the chosen interpolation space.

Known issues & limitations

  • The performance in Vello is not the best. We should replace it with the rasterization version in the future.
  • No support for polar color spaces for interpolation. In the 2D color space, the shorter/longer path of the interpolation can cause contradictions.
  • Banding occurs in SVG when the patch size is large and strongly warped in both shape and color. This happens because the supported color bit depth for the displacement map is 8 bits per channel, which is sometimes insufficient for such a situation. This can technically be solved by subdividing the patch since a source and target size of at least 128x128px cannot cause the banding issue.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new "Mesh" gradient type, adding UI support in the gradient tool and implementing an initial SVG rendering path that approximates the mesh by subdividing it into an 8x8 grid of polygons. Feedback identifies critical bugs in the rendering logic, including potential panics if the geometry has fewer than four points or segments and an incorrect return statement that prevents subsequent elements from rendering. Additionally, the reviewer noted that the mesh colors are currently hardcoded and that the Vello and SVG stops table implementations are still placeholders.

Comment thread node-graph/libraries/rendering/src/renderer.rs Outdated
Comment thread node-graph/libraries/rendering/src/renderer.rs Outdated
Comment thread node-graph/libraries/rendering/src/renderer.rs Outdated
Comment thread node-graph/libraries/rendering/src/renderer.rs Outdated
Comment thread node-graph/libraries/rendering/src/renderer.rs Outdated
@Keavon
Keavon force-pushed the master branch 2 times, most recently from 4b7a823 to 847b8e9 Compare May 17, 2026 14:37
@timon-schelling
timon-schelling force-pushed the master branch 2 times, most recently from 15fcaac to d5f0140 Compare May 17, 2026 15:37
@YohYamasaki
YohYamasaki force-pushed the mesh-gradient-poc branch 2 times, most recently from 5785002 to 231773c Compare July 17, 2026 04:30
@YohYamasaki
YohYamasaki force-pushed the mesh-gradient-poc branch 2 times, most recently from 6575890 to f097784 Compare July 23, 2026 03:21
@YohYamasaki YohYamasaki mentioned this pull request Aug 6, 2026
- Click to add/select mesh gradient
- Show transform widget inside Fill nodes
# Conflicts:
#	editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs
#	editor/src/messages/portfolio/document/graph_operation/graph_operation_message.rs
#	editor/src/messages/portfolio/document/graph_operation/utility_types.rs
#	editor/src/messages/portfolio/document/node_graph/node_properties.rs
#	editor/src/messages/portfolio/document_migration.rs
#	node-graph/libraries/graphic-types/src/graphic.rs
#	node-graph/libraries/rendering/src/render_ext.rs
#	node-graph/libraries/rendering/src/renderer.rs
#	node-graph/nodes/path-bool/src/lib.rs
#	node-graph/nodes/vector/src/vector_nodes.rs
@YohYamasaki

Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai Please review

@cubic-dev-ai

cubic-dev-ai Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai Please review

@YohYamasaki I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 36 files

Tip: cubic used a learning from your PR history. Let your coding agent read cubic learnings directly with the cubic MCP.

Re-trigger cubic

Comment thread editor/src/messages/portfolio/document_migration.rs
Comment thread editor/src/messages/tool/tool_messages/mesh_gradient_tool.rs Outdated
Comment thread editor/src/messages/tool/tool_messages/mesh_gradient_tool.rs
Comment thread node-graph/libraries/rendering/src/renderer/mesh_gradient.rs Outdated
Comment thread node-graph/libraries/vector-types/src/mesh_gradient.rs
Comment thread editor/src/messages/portfolio/document_migration.rs
Comment thread editor/src/messages/tool/tool_messages/mesh_gradient_tool.rs
Comment thread node-graph/libraries/rendering/src/renderer/mesh_gradient.rs Outdated
Comment thread node-graph/libraries/graphic-types/src/graphic.rs
@YohYamasaki YohYamasaki changed the title Mesh gradient Add mesh gradient support Aug 17, 2026
# Conflicts:
#	node-graph/libraries/graphic-types/src/graphic.rs
#	node-graph/libraries/rendering/src/render_ext.rs
#	node-graph/libraries/rendering/src/renderer.rs
#	node-graph/nodes/path-bool/src/lib.rs
@YohYamasaki

Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai Please review

@cubic-dev-ai

cubic-dev-ai Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai Please review

@YohYamasaki I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 36 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread node-graph/libraries/rendering/src/renderer.rs
Comment thread node-graph/libraries/rendering/src/renderer/mesh_gradient.rs
Comment thread node-graph/libraries/graphic-types/src/graphic.rs Outdated
Comment thread editor/src/messages/tool/tool_messages/mesh_gradient_tool.rs
Comment thread node-graph/libraries/vector-types/src/mesh_gradient.rs Outdated
Comment thread node-graph/libraries/vector-types/src/mesh_gradient.rs
@YohYamasaki
YohYamasaki marked this pull request as ready for review August 17, 2026 12:11

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 36 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread editor/src/messages/tool/tool_messages/mesh_gradient_tool.rs
Comment thread editor/src/messages/tool/tool_messages/mesh_gradient_tool.rs
Comment thread node-graph/libraries/graphic-types/src/graphic.rs
Comment thread node-graph/libraries/vector-types/src/mesh_gradient.rs
Comment thread node-graph/libraries/vector-types/src/mesh_gradient.rs Outdated
Comment thread node-graph/libraries/vector-types/src/mesh_gradient.rs
# Conflicts:
#	editor/src/messages/portfolio/document/storage_tests/round_trip_tests.rs
#	node-graph/libraries/graphic-types/src/appearance.rs
#	node-graph/nodes/graphic/src/graphic.rs
#	node-graph/nodes/vector/src/vector_nodes.rs

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread editor/src/messages/tool/tool_messages/mesh_gradient_tool.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mesh gradients

1 participant