Skip to content

feat(shader_material): modulate2x blend — dst * 2 * src, for lighting overlays - #81

Merged
apotema merged 1 commit into
mainfrom
feat/modulate2x-blend
Sep 24, 2026
Merged

apotema merged 1 commit into
mainfrom
feat/modulate2x-blend

Conversation

@apotema

@apotema apotema commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Adds Blend.modulate2x to game-owned shader materials: each RGB channel of what is already drawn is multiplied by 2 * src, and the destination alpha is kept. A source of 0.5 leaves the pixel unchanged, 0 blacks it out, 1 doubles it.

Why: Flying Platform is moving its night lighting from a shader on every lit sprite to one baked light overlay per room (one quad drawn over the room's contents). An overlay has to both darken (the 60% ambient) and brighten (lamp beams, up to ~1.5x) whatever is under it. Alpha and additive blending can't do that; a 2x multiply can. On an SM-T505 this takes a 17-room night scene from 31.6 ms to 16.7 ms a frame, and a 1000-citizen colony from a frozen ~400 ms to normal frame times.

Compatibility: additive enum value; the default stays .alpha. Backends that switch exhaustively on Blend need the new case: labelle-bgfx gets it in a companion PR (the (DstColor, SrcColor) / (Zero, One) blend state). The assembler's material.json schema gets "blend": "modulate2x" in its own PR.

Tests: zig build test 230/230. The bgfx companion builds and passes 253/253 against this branch (-Dcore-source).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

… overlays

A material that must both darken and brighten what is under it (baked
room lighting drawn as one overlay quad over batched sprites) cannot do
it with alpha or additive blending. modulate2x multiplies each RGB
channel by 2*src (0.5 = unchanged) and keeps the destination alpha.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-24T17:47:19.963372Z c481b7b PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: c524ecdb-3dd4-4c4a-a790-8f8c250bfad9

📥 Commits

Reviewing files that changed from the base of the PR and between 1cd1942 and c481b7b.

📒 Files selected for processing (1)
  • src/shader_material.zig

Included review availability: 0 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.


📝 Walkthrough

Walkthrough

The Blend enum adds a modulate2x option. Its documentation describes RGB output as destination color multiplied by twice the source color, with destination alpha preserved and shader alpha ignored.

Changes

Blend option

Layer / File(s) Summary
Add the modulate2x blend option
src/shader_material.zig
Blend adds the modulate2x variant. Its documentation describes RGB and alpha handling and the output for overlay values 0.5, 0, and 1.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to c481b

This change adds the documented blend option, and the reviewed repository shows no actionable build or rendering issue. Mergeability risk is minimal.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the addition of modulate2x blending and states its main behavior and intended lighting-overlay use.
Description check ✅ Passed The description directly explains the Blend.modulate2x change, its rendering behavior, motivation, compatibility impact, and reported test results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@apotema
apotema merged commit ef147b6 into main Sep 24, 2026
4 checks passed
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.

1 participant