Add blend modes math reference guide#129
Open
JOYBOY-0 wants to merge 7 commits into
Open
Conversation
Concise per-channel formulas for the common layer blend modes (multiply, screen, overlay, soft light, etc.), framed for shader work in linear space.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
||
| ### 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. |
Contributor
There was a problem hiding this 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.
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.
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.
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.
Summary
Added a comprehensive reference guide documenting the mathematical formulas behind common layer blend modes used in shader work and graphics programming.
Changes
content/logs/14-blend-modes-math.mdxNotable Details
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.
step-based overlay) are accurate.a = 0.5is the no-op; the actual neutral color isb = 0.5(a 50% grey blend layer leaves the base unchanged), and this distinction matters since Hard Light — correctly identified as the swapped variant — usesa = 0.5as 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
a = 0.5instead ofb = 0.5.Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "Add log 14: blend modes math glossary" | Re-trigger Greptile