Skip to content

Add blend modes math reference guide#129

Open
JOYBOY-0 wants to merge 7 commits into
mainfrom
claude/blend-modes-math-glossary-R8onw
Open

Add blend modes math reference guide#129
JOYBOY-0 wants to merge 7 commits into
mainfrom
claude/blend-modes-math-glossary-R8onw

Conversation

@JOYBOY-0

@JOYBOY-0 JOYBOY-0 commented May 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Added a comprehensive reference guide documenting the mathematical formulas behind common layer blend modes used in shader work and graphics programming.

Changes

  • New log entry: content/logs/14-blend-modes-math.mdx
    • Quick glossary of blend mode formulas with practical explanations
    • Coverage of 15+ blend modes including multiply, screen, overlay, soft light, color dodge/burn, and more
    • Pattern documentation showing mathematical relationships between related blend modes
    • Opacity blending explanation with common implementation mistakes
    • GLSL shader code examples for practical implementation
    • Emphasis on linear color space requirements and per-channel operation

Notable Details

  • Clarifies that blend modes are per-channel functions and names are conventions while formulas are definitive
  • Highlights the multiply ↔ screen duality and other mathematical relationships
  • Addresses the opacity blending mistake (applying opacity after the blend function, not before)
  • Notes that soft light has multiple variants (Photoshop, W3C, Pegtop) and recommends documenting which is used
  • Includes practical guidance on clamping for unbounded operations (add, color dodge/burn)

https://claude.ai/code/session_01VvwH3WmqcoMB2AKPvdbt8P

Greptile Summary

Adds a new MDX log entry documenting the mathematical formulas behind 15 common layer blend modes, with GLSL shader examples, an opacity-blending explanation, and notes on linear color space requirements.

  • All blend mode formulas are mathematically correct, and the GLSL implementations (including the branchless step-based overlay) are accurate.
  • The Overlay section incorrectly states that a = 0.5 is the no-op; the actual neutral color is b = 0.5 (a 50% grey blend layer leaves the base unchanged), and this distinction matters since Hard Light — correctly identified as the swapped variant — uses a = 0.5 as its neutral.

Confidence Score: 3/5

The file is a developer reference guide — the factual error in the Overlay section would mislead readers about which variable carries the neutral color, and the distinction is meaningful when implementing blend modes by hand.

The rest of the formulas, GLSL snippets, and prose are accurate, but the Overlay no-op claim gets the wrong variable (a vs b), which is a concrete factual mistake in a document whose primary purpose is to be a correct reference.

content/logs/14-blend-modes-math.mdx — specifically the Overlay section's neutral-color claim

Important Files Changed

Filename Overview
content/logs/14-blend-modes-math.mdx New blend modes reference guide — all formulas correct except the Overlay neutral-color claim, which incorrectly attributes the no-op condition to a = 0.5 instead of b = 0.5.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
content/logs/14-blend-modes-math.mdx:41
The "no-op" claim refers to the wrong variable. When `a = 0.5`, both branches of the Overlay formula reduce to `b`, meaning the base passes through the blend layer unchanged — that's not a no-op, it's a passthrough. The actual neutral/no-op condition for Overlay is when **`b = 0.5`**: plugging in `b = 0.5` gives `2*a*0.5 = a` (dark branch) and `1 - 2*(1-a)*0.5 = a` (bright branch), so the blend layer has zero effect on the base. This matches how Photoshop documents it — a 50% grey layer in Overlay mode leaves the composition unchanged.

```suggestion
Multiply on the dark half of `a`, screen on the bright half. `b = 0.5` is the no-op (a 50% grey blend layer leaves the base unchanged). **Hard Light** is the same formula with `a` and `b` swapped — the blend picks the branch instead of the base, so `a = 0.5` becomes its no-op.
```

Reviews (1): Last reviewed commit: "Add log 14: blend modes math glossary" | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Concise per-channel formulas for the common layer blend modes (multiply,
screen, overlay, soft light, etc.), framed for shader work in linear space.
@vercel

vercel Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
joyco-hub Ready Ready Preview, Comment May 8, 2026 6:35pm

Comment thread content/logs/14-blend-modes-math.mdx Outdated

### Overlay — `a < 0.5 ? 2*a*b : 1 - 2*(1 - a)*(1 - b)`

Multiply on the dark half of `a`, screen on the bright half. `a = 0.5` is the no-op. **Hard Light** is the same formula with `a` and `b` swapped — the blend picks the branch instead of the base.

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.

P1 The "no-op" claim refers to the wrong variable. When a = 0.5, both branches of the Overlay formula reduce to b, meaning the base passes through the blend layer unchanged — that's not a no-op, it's a passthrough. The actual neutral/no-op condition for Overlay is when b = 0.5: plugging in b = 0.5 gives 2*a*0.5 = a (dark branch) and 1 - 2*(1-a)*0.5 = a (bright branch), so the blend layer has zero effect on the base. This matches how Photoshop documents it — a 50% grey layer in Overlay mode leaves the composition unchanged.

Suggested change
Multiply on the dark half of `a`, screen on the bright half. `a = 0.5` is the no-op. **Hard Light** is the same formula with `a` and `b` swapped — the blend picks the branch instead of the base.
Multiply on the dark half of `a`, screen on the bright half. `b = 0.5` is the no-op (a 50% grey blend layer leaves the base unchanged). **Hard Light** is the same formula with `a` and `b` swapped — the blend picks the branch instead of the base, so `a = 0.5` becomes its no-op.
Prompt To Fix With AI
This is a comment left during a code review.
Path: content/logs/14-blend-modes-math.mdx
Line: 41

Comment:
The "no-op" claim refers to the wrong variable. When `a = 0.5`, both branches of the Overlay formula reduce to `b`, meaning the base passes through the blend layer unchanged — that's not a no-op, it's a passthrough. The actual neutral/no-op condition for Overlay is when **`b = 0.5`**: plugging in `b = 0.5` gives `2*a*0.5 = a` (dark branch) and `1 - 2*(1-a)*0.5 = a` (bright branch), so the blend layer has zero effect on the base. This matches how Photoshop documents it — a 50% grey layer in Overlay mode leaves the composition unchanged.

```suggestion
Multiply on the dark half of `a`, screen on the bright half. `b = 0.5` is the no-op (a 50% grey blend layer leaves the base unchanged). **Hard Light** is the same formula with `a` and `b` swapped — the blend picks the branch instead of the base, so `a = 0.5` becomes its no-op.
```

How can I resolve this? If you propose a fix, please make it concise.

Restructure as: short intro framing what a blend mode is, contract
section (linear space + opacity-lerp gotcha), reference table of
formulas, three "duals to memorize" subsections, single GLSL block,
and a list of common mistakes. Voice/components aligned with logs
10–13.
12-mode gallery using a shared horizontal black→white gradient as the
base, so each cell reads left-to-right as the formula evaluated across
the full luminance range. Top layer is switchable between solid, RGB
bars, and a vertical color gradient — easier to predict and compare than
MDN's static photo grid. Each card shows the mode name plus a short
formula caption.
claude added 2 commits May 8, 2026 18:07
The no-op condition is when the blend is 50% grey (b = 0.5), not the
base. With a = 0.5 both branches collapse to b — passthrough of blend,
not no-op. Hard Light also has its no-op at b = 0.5 per W3C spec
(matches Photoshop's "50% grey layer = no effect").
Switch from stacked DOM nodes with mix-blend-mode to a single element
per cell using background-blend-mode — one paint op per cell instead
of forcing the browser to create a stacking context per overlay. Wrap
the demo in isolation: isolate so the blend math doesn't reach into
the surrounding page composition. Add contain: paint per cell.

Styling: drop rounded corners on the gallery (matches registry preview
which uses sharp corners), use the project's Button component for the
preset toggle, mono uppercase labels with the same vocabulary as
image-sequence-demo and spritesheet-sequencer-demo.
- Swap the bespoke button strip for the project's Tabs/TabsList/
  TabsTrigger (mono uppercase, matches the registry's tab styling).
- Drop the card chrome and hairline-border grid; cells are now bare
  preview + label, with gap-x-5 gap-y-7 between them. Matches the
  spacing pattern in image-sequence-demo and spritesheet-sequencer-demo.
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