Skip to content

Make grain-gradient WebGL-only v2 - #16

Merged
aomona merged 4 commits into
mainfrom
feature/webgl-v2
Jul 8, 2026
Merged

Make grain-gradient WebGL-only v2#16
aomona merged 4 commits into
mainfrom
feature/webgl-v2

Conversation

@aomona

@aomona aomona commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Make v2 WebGL-only by removing CSS/SVG generation and Android/canvas fallback APIs
  • Replace the playground with a React/Vite WebGL playground
  • Harden React/WebGL context lifecycle, seed handling, square grain coordinates, and docs/tests for the v2 contract

Test Plan

  • npm run typecheck
  • npm run build
  • npm test
  • npm run build:playground
  • npm run lint
  • npm run format:check

@aomona
aomona requested a review from Copilot July 8, 2026 09:14
@aomona

aomona commented Jul 8, 2026

Copy link
Copy Markdown
Owner Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR upgrades grain-gradient to v2 by making the library WebGL-only, removing the prior CSS/SVG + Android/canvas fallback surface area, and replacing the old playground with a Vite/React WebGL playground. It also updates docs and tests to reflect the new v2 contract and hardens the WebGL renderer’s lifecycle and shader behavior.

Changes:

  • Remove legacy CSS/SVG generation and canvas/Android fallback APIs; make the main entry export the WebGL renderer API.
  • Update the WebGL shader + CPU-side motion/grain handling (seed normalization, square grain normalization, CPU trig uniforms).
  • Replace the playground with a React/Vite implementation and update docs/tests/workflows accordingly.

Reviewed changes

Copilot reviewed 17 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vite.config.ts Adds Vite config targeting the new playground/ root and outputs to dist-playground/.
tests/library.test.mjs Rewrites tests to assert v2 exports (WebGL-only) and validates shader/perf invariants.
src/webgl.ts Implements the WebGL shader renderer changes (grain shader, CPU motion uniforms, option normalization).
src/webgl-react.tsx Simplifies the legacy webgl/react entry to re-export the main React component API.
src/react.tsx Replaces CSS/SVG layering with a WebGL-canvas React component and improved context lifecycle handling.
src/internal.ts Simplifies swirl normalization and motion normalization helpers used by WebGL.
src/index.ts Re-exports WebGL API from the main entrypoint.
src/core.ts Removes legacy CSS/SVG/canvas fallback types/APIs and introduces v2 option types (mesh/motion/grain).
README.md Updates positioning, examples, and playground link for v2 WebGL-only contract.
playground/tsconfig.json Adds TypeScript config for the new Vite/React playground.
playground/src/styles.css Adds standalone CSS styling for the new playground UI.
playground/src/main.tsx New React entrypoint bootstrapping the playground app.
playground/src/App.tsx Implements the new playground UI and WebGL renderer lifecycle handling.
playground/index.html Replaces the old large static HTML playground with a minimal Vite/React root.
package.json Bumps to v2.0.0, adds Vite/React playground build scripts and dependencies.
package-lock.json Updates lockfile for new dependencies (Vite React plugin, react-dom, types).
docs/API.md Rewrites API reference for the WebGL-only v2 surface area and compatibility subpaths.
.gitignore Ignores dist-playground/ output and an additional .slim/deepwork/ path.
.github/workflows/pages.yml Updates Pages build to build and publish the Vite playground output from dist-playground/.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/internal.ts Outdated
Comment on lines +4 to +8
@@ -5,24 +5,9 @@ export type MotionPreset = "none" | "drift" | "breathe" | "orbit";

export const normalizeSwirl = (swirl = 0) => {
const value = clamp(swirl, 0, 100);
const shift = value / 100;
return {
value,
enabled: value > 0,
scale: (1 + value * 0.004).toFixed(3),
rotate: (value * 0.12).toFixed(2),
offsetX: shift * 12,
offsetY: shift * -10,
backgroundSizeX: (100 + value * 0.55).toFixed(1),
backgroundSizeY: (100 + value * 0.4).toFixed(1),
backgroundPositionX: (50 + shift * 12).toFixed(1),
backgroundPositionY: (50 - shift * 10).toFixed(1),
};
return { value, enabled: value > 0 };
Comment on lines 25 to 28
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
with:
node-version: 20
cache: npm

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dc945d4482

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/webgl.ts Outdated
swirlScale = 1.0 + swirl.value * 0.004;
rotateRad = (Number(motion.rotate) * Math.PI) / 180;
zoom = motion.enabled ? Number(motion.zoom) : 1;
travel = Number(motion.travel) / 100;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Zero travel for static renders

When motionPreset is "none" or motion is disabled by zero speed/intensity, normalizeMotion still returns a nonzero default travel (12% at default intensity), and render() applies it as frameTravelY = travel * orbit even for the one static draw. This makes the default/static gradient render shifted vertically and can make it jump on later resize()/update() calls; travel should be set to 0 when motion.enabled is false, similar to motionAmount.

Useful? React with 👍 / 👎.

@aomona
aomona merged commit 67071d0 into main Jul 8, 2026
1 check passed
@aomona
aomona deleted the feature/webgl-v2 branch July 8, 2026 09:47
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.

2 participants