Repository navigation
feat(dither): Dither layer with colors, shader and 17 patterns on one WebGL context - #1048
Merged
dillionverma merged 9 commits intoNov 26, 2026
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
dillionverma
marked this pull request as ready for review
November 26, 2026 00:49
Add 12 palette patterns to DitherField: gruvbox-dusk, nord-orbit, kanagawa-moonrise, orbit, meridian, eclipse-rose, ridgeline, contour, dunes, eclipse-nord, orb and veil. Each one ships its own colors, Bayer matrix and dot size. New optional props: palette and matrix. dotSize is now optional. Existing props and patterns are unchanged. All instances share one WebGL2 context and compile shaders in the background, so the docs page holds 1 live context instead of up to 8. Add 12 installable examples (dither-<pattern>) and a Patterns section in the docs page. Regenerate the registry files. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… single-field cost - Rename DitherField to Dither: component, registry item, docs page and the nine examples (dither-field-* to dither-*). No alias, no redirect. - Retry the pending draw until the first frame presents, so a still field (speed 0 or an image src) no longer stays blank while a shader compiles. - Mark the entry failed when createProgram returns null, so the CSS fallback shows. - Replace the bitwise AND in the noise table with a modulo. - A field that has the shared hub to itself now shows the hub canvas directly. Only a second field makes each one copy its rectangle into a 2D canvas. This removes the drawImage copy from the one-hero case. - Veil footer example: text on top, beams below, so the dither fills the card. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
When two fields drop to one, the survivor now moves from its 2D copy back onto the shared WebGL canvas. releaseHub() calls attach() on the last member. Renderer setMedia and dispose are optional, so the scene renderer no longer carries empty method bodies. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…erns grid Examples now show card backgrounds, a mouse interaction on/off toggle, a text mask and an image. A Patterns section shows all 17 patterns as same-size tiles that share one WebGL context. Remove the 12 per-pattern examples and the monochrome, brand and colors demos. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… in patterns
- `interactive` now defaults to false. The card and mouse demos set it.
- The patterns grid has 2 columns, and each tile uses `dotSize={1}`.
- Add a `uUnit` uniform so scene shapes keep their size at any dot size.
- Brighten the orbit ring so it reaches the accent color at tile size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dither is now a layer that fills its positioned parent and takes no children. One `colors` prop replaces the single-color and palette props. A `shader` prop takes GLSL that defines `float field(vec2 uv, float t)`. Each unique string compiles once. A compile error logs its line and sets data-state="fallback". All 17 built-in patterns use the same contract. Five palette ids change: gruvbox-dusk is sunset, nord-orbit is planet, kanagawa-moonrise is moonrise, eclipse-rose is eclipse and eclipse-nord is corona. The repaint callback is no longer empty. The examples move to the layer API and a dither-shader-demo example is added. color props, five pattern ids are renamed and dotSize defaults to 1. 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>
dillionverma
force-pushed
the
bb/expand-and-optimize-ditherfield-component-thr_afpfn4ddmv
branch
from
November 26, 2026 00:53
a65a55d to
c096ab2
Compare
dillionverma
deleted the
bb/expand-and-optimize-ditherfield-component-thr_afpfn4ddmv
branch
November 26, 2026 01:03
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
Ditheris a layer. It fills its positioned parent and takes no children. It has 17 built-in patterns, an image or videosrc, and a newshaderprop for your own GLSL. Onecolorsprop takes one color or a list of stops. All instances share one WebGL2 context.API
The root is
<div data-slot="dither" data-state="pending | ready | fallback" aria-hidden>withpointer-events-none absolute inset-0 overflow-hidden rounded-[inherit]. It forwardsrefand mergesclassName.pattern,srcandshaderare exclusive at the type level.dither.type-test.tsxhas a@ts-expect-errorline for each pair and for children.Shader contract
uvruns from 0 to 1 from the bottom-left corner.tis seconds timesspeed. The return value is brightness from 0 to 1, mapped ontocolors.uSize,uAspect,uDot,uPointer,uPointerOn,noise,fbmandss.Dither: the shader did not compile.and the error with its line number in your source. The layer stays blank and getsdata-state="fallback".All 17 built-in patterns now use this same contract. Light patterns dither in
colorsover a clear background. Palette patterns keep their own ground, colors and matrix, andcolorsrecolors them.Files to review
Core:
apps/www/registry/magicui/dither.tsx. The component, the shared WebGL2 hub, the 17 field shaders and the shader error report.apps/www/registry/magicui/dither.type-test.tsx. The type test for the exclusive source props.apps/www/content/docs/components/dither.mdx. Docs in the same layout as the other component pages.apps/www/registry/example/dither-*.tsx. The 6 examples moved to the layer API, plus the newdither-shader-demo.Generated by
pnpm build:registry:registry.json,apps/www/registry.json,apps/www/registry/__index__.tsx,apps/www/public/r/*,apps/www/public/registry.jsonandapps/www/public/llms*.txt.Docs page
dither-shader-demo, warped ribbons in--primary).DITHER_PATTERNS. All tiles share one WebGL context.Notes and limits
DITHER_PATTERNScomes from a"use client"module. A server component gets a client reference, so.mapfails there.dither-patterns-demois a client component for this reason.Rendering fixes from earlier commits
speed={0}or an imagesrc) stayed blank when the shader compiled after the first draw. The retry now runs until the first frame is on screen.createProgram()returns null, the field is marked failed and the CSS fallback shows.% 256instead of& 255.Performance
These numbers come from an earlier commit on this branch, before the layer API. The hub and the context model did not change after that commit.
All instances share one WebGL2 context, and shaders compile in the background (
KHR_parallel_shader_compile). Before, each instance made its own context and compiled two programs on every scroll-in.getContextcallsFor one large hero instance, the CPU busy time per frame is about the same as
main. At 1920x1080, DPR 2 and 30 fps, the medians are 1.43 ms on this branch and 1.39 ms onmain, and the run ranges overlap. A field that is alone on the shared context shows that canvas directly and skips the copy. With several fields, each field copies its own rectangle.Kept as before: reduced motion (still frame), off-screen pause, hidden-tab pause, SSR safety, DPR and resize handling, and the CSS fallback when WebGL2 is missing or the context is lost.
Checks
eslint,tsc --noEmit,prettier --checkandregistry-deps --checkpass. Thepnpm build:registryoutput is committed.rg -n "gruvbox|nord-orbit|kanagawa|eclipse-rose|eclipse-nord|palette=|color=" apps/www/registry apps/www/content/docs/components/dither.mdxfinds no Dither match.@ts-expect-errorline is removed from the type test, tsc gives TS2322.ribbnforribbon) logsline 6: 'ribbn' : undeclared identifierand setsdata-state="fallback".