Skip to content

feat(canvas): draw quads and sprites through compiled shaders - #2506

Merged
oneo-me merged 4 commits into
mainfrom
agiox/canvas-shader-drawing
Nov 26, 2026
Merged

oneo-me merged 4 commits into
mainfrom
agiox/canvas-shader-drawing

Conversation

@oneo-me

@oneo-me oneo-me commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #2260

A Canvas drawing can now run a compiled ShaderProgram in its order, under its transform, clip, alpha and composite operator.

  • program.Paint(uniforms, images...) makes a core.ShaderPaint. An AnimatedNode uniform becomes a drawing slot (ArgLane), so it redraws on the frame clock without a commit.
  • Drawing.DrawShader(paint, x, y, w, h) shades a rectangle, with pos in its own points.
  • Drawing.SetShader(paint) / ClearShader() shade the images that DrawImage*, DrawAtlas and DrawVertices draw. Save and Restore keep the setting. The drawn image is image0, read at dst.xy in its pixels. A whole run of SDF glyphs is one DrawAtlas op and one GPU pass.
  • internal/platform/canvasshade lays out each shaded op as one pass in the target's pixels. Each backend renders that pass into a texture and the canvas player draws it in device space:
    • Metal on Apple platforms, read back.
    • Direct3D 11 on the device Direct2D shares, with no readback.
    • OpenGL on Linux, read back.
    • WebGL 2 on the web, drawn into the 2D context.
  • Android, HarmonyOS, watchOS and mini programs leave DrawShader out and draw shaded images plain. This is recorded in the roadmap.

Tests

  • canvastest.Shading is a shared sample. It checks:
    • SDF glyphs crisp at 1x, 4x and rotated.
    • Two runs with different color and outline in one drawing.
    • Draw order against fills.
    • Clip, alpha, destination-over, rotation and stretched pos / rectSize.
  • The sample passes in the Apple, Windows and Linux package tests.
  • The capture test TestCanvasShading passes on macOS, the iOS simulator, the web (headless Chrome), Windows 11, and Linux under Wayland, X11 and llvmpipe.
  • BenchmarkPlayAtlas / BenchmarkPlayShadedAtlas (500 glyphs):
Backend Plain atlas Shaded atlas
Apple M1 Max 3.1 ms 2.8 ms
Windows 34 µs 303 µs
Linux 1.9 ms 2.3 ms

🤖 Generated with Claude Code

🤖 Claude Opus 5.5

@oneo-me oneo-me self-assigned this Nov 26, 2026
@github-actions github-actions Bot added enhancement New feature or request size/XS documentation Improvements or additions to documentation macOS iOS Web Android core size/XL Windows Linux and removed size/XS labels Nov 26, 2026
@oneo-me
oneo-me marked this pull request as ready for review November 26, 2026 10:48
oneo-me and others added 4 commits November 26, 2026 19:07
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oneo-me
oneo-me force-pushed the agiox/canvas-shader-drawing branch from a76728f to 39b495b Compare November 26, 2026 11:07
@oneo-me
oneo-me enabled auto-merge (rebase) November 26, 2026 11:07
@github-actions github-actions Bot added the cli label Nov 26, 2026
@oneo-me
oneo-me merged commit d463d00 into main Nov 26, 2026
44 checks passed
@oneo-me
oneo-me deleted the agiox/canvas-shader-drawing branch November 26, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Canvas: draw an image or quad through a compiled shader with uniforms

1 participant