Skip to content

New node: 'Mesh Gradient Value' - #4081

Draft
YohYamasaki wants to merge 16 commits into
GraphiteEditor:masterfrom
YohYamasaki:mesh-gradient-poc
Draft

YohYamasaki wants to merge 16 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-09-23.at.21.38.56.mp4

Add Coons patch-based mesh gradient paint and an experimental editing tool.

Neither Vello nor SVG has native rendering support for mesh gradients, so we rasterize them by the custom pipeline. The SVG export has an option to use displacement map method instead.

Known limitations

  • The SVG displacement-map method may show banding on large, strongly warped patches because it uses 8-bit displacement channels. Also it is unstable because of the implementation differences between browsers.
  • Rasterization does not yet account for attributes applied downstream of the Mesh Gradient Value nodes, currently default to fitting the paint target's bounding box.

@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
@YohYamasaki
YohYamasaki force-pushed the mesh-gradient-poc branch 2 times, most recently from e5de2e0 to ededf6c Compare August 9, 2026 12:44
@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 Outdated
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 Outdated
Comment thread node-graph/libraries/rendering/src/renderer/mesh_gradient.rs Outdated
Comment thread node-graph/libraries/vector-types/src/mesh_gradient.rs Outdated
Comment thread editor/src/messages/portfolio/document/node_graph/node_properties.rs Outdated
Comment thread editor/src/messages/portfolio/document_migration.rs Outdated
Comment thread editor/src/messages/tool/tool_messages/mesh_gradient_tool.rs Outdated
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
@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 Outdated
Comment thread node-graph/libraries/rendering/src/renderer/mesh_gradient.rs Outdated
Comment thread editor/src/messages/tool/common_functionality/graph_modification_utils.rs Outdated
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 Outdated
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 Outdated
Comment thread node-graph/libraries/vector-types/src/mesh_gradient.rs Outdated
Comment thread node-graph/libraries/vector-types/src/mesh_gradient.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

@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.

1 issue found across 2 files (changes from recent commits).

Confidence score: 3/5

  • In node-graph/libraries/rendering/src/renderer/mesh_gradient.rs, the guard accepts a singular parent_transform * mesh_transform when both columns are nonzero, allowing a collapsed output transform to reach displacement-map construction and potentially produce incorrect rendering; check the smallest singular value before proceeding.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="node-graph/libraries/rendering/src/renderer/mesh_gradient.rs">

<violation number="1" location="node-graph/libraries/rendering/src/renderer/mesh_gradient.rs:1025">
P2: When `parent_transform * mesh_transform` is singular but both columns are nonzero, this guard accepts a collapsed output transform and proceeds to build the displacement map. Check the smallest singular value before rendering the patch.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread node-graph/libraries/rendering/src/renderer.rs Outdated
// so a local space that reaches the output non-uniformly displaces both axes by the wrong amount there.
let mesh_to_output = (self.parent_transform * self.mesh_transform).matrix2;
let output_scales = DVec2::new(mesh_to_output.x_axis.length(), mesh_to_output.y_axis.length());
if !output_scales.is_finite() || output_scales.min_element() <= f64::EPSILON {

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.

P2: When parent_transform * mesh_transform is singular but both columns are nonzero, this guard accepts a collapsed output transform and proceeds to build the displacement map. Check the smallest singular value before rendering the patch.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At node-graph/libraries/rendering/src/renderer/mesh_gradient.rs, line 1025:

<comment>When `parent_transform * mesh_transform` is singular but both columns are nonzero, this guard accepts a collapsed output transform and proceeds to build the displacement map. Check the smallest singular value before rendering the patch.</comment>

<file context>
@@ -1009,15 +1016,20 @@ impl<'mesh, 'field> SvgMeshPatchRenderer<'mesh, 'field> {
+		// so a local space that reaches the output non-uniformly displaces both axes by the wrong amount there.
+		let mesh_to_output = (self.parent_transform * self.mesh_transform).matrix2;
+		let output_scales = DVec2::new(mesh_to_output.x_axis.length(), mesh_to_output.y_axis.length());
+		if !output_scales.is_finite() || output_scales.min_element() <= f64::EPSILON {
 			return;
 		}
</file context>

@YohYamasaki

Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai Please review

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 23, 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 68 files

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

Re-trigger cubic

Comment thread node-graph/nodes/gradient/src/mesh_gradient/mod.rs
Comment thread node-graph/nodes/gstd/src/render_node.rs
Comment thread node-graph/nodes/gradient/src/mesh_gradient/cache.rs
Comment thread editor/src/messages/tool/tool_messages/mesh_gradient_tool.rs
Comment thread node-graph/libraries/core-types/src/lib.rs
Comment thread node-graph/libraries/graphene-cache/Cargo.toml
Comment thread node-graph/libraries/vector-types/Cargo.toml Outdated
Comment thread node-graph/libraries/core-types/src/list.rs Outdated
Comment thread node-graph/libraries/core-types/src/context.rs Outdated
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@YohYamasaki YohYamasaki changed the title Add mesh gradient support New node: 'Mesh Gradient Value' Sep 23, 2026
@Keavon

Keavon commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

!build (Run ID 35975976695)

@github-actions

Copy link
Copy Markdown
📦 Web Build Complete for bc5d8d3
https://844fa921.graphite.pages.dev

Wasm: 40.62 MB — JS: 0.46 MB — CSS: 0.09 MB — Fonts: 0.30 MB — Images: 0.09 MB — All Assets: 41.57 MB

This branch has not been deployed

No deployments
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

2 participants