Skip to content

Add --opaque flag to screenshot for shaders that write alpha=0#2

Open
arghhhhh wants to merge 1 commit into
0dot77:mainfrom
arghhhhh:feat/screenshot-opaque
Open

Add --opaque flag to screenshot for shaders that write alpha=0#2
arghhhhh wants to merge 1 commit into
0dot77:mainfrom
arghhhhh:feat/screenshot-opaque

Conversation

@arghhhhh

Copy link
Copy Markdown

Problem

Many TD shaders write fragColor with alpha = 0 — atmospheric/sky shaders that use alpha as a compositing-flag, GLSL templates that simply omit the alpha component, etc. The captured PNG is technically correct (RGBA where A=0) but most image viewers composite RGBA over white when alpha=0, producing a blank-looking image and hiding the actual RGB content.

This is especially confusing because TD's own node-viewer thumbnail ignores alpha and shows RGB directly — so the artist sees a perfectly-rendered sky in the network while the saved PNG looks completely white.

Concretely: I'm using td-cli to drive an LLM agent's visual feedback loop. The agent was repeatedly drawing wrong conclusions about a sky shader because every td-cli screenshot came back blank-white in its viewer, even though the shader was working fine. Sampling pixel values via td-cli exec confirmed real RGB data with alpha=0.

Fix

New --opaque flag on screenshot:

td-cli screenshot /project1/sky/glsl1 --opaque -o sky.png

Implementation:

  • Go-side post-processing — decode the PNG returned by the handler, force alpha to 255 on every pixel, re-encode.
  • RGB channels preserved as-is (no premultiplied-alpha unpacking — matches what TD's node viewer displays).
  • Zero TD-side / handler changes, so it works against every existing handler version.
  • Default behavior unchanged.

Test plan

  • Builds clean with go build ./cmd/td-cli/
  • Verified against a live Nishita sky shader (fragColor = vec4(scattering, 0.0)) — default capture renders white in viewers, --opaque reveals the real RGB
  • Default screenshot (no flag) produces byte-identical output to pre-patch
  • Handler-side path untouched, but worth a sanity check on a TOP that already writes alpha=1 to confirm --opaque is a no-op for it

Notes

Help text updated in cmd/td-cli/main.go. Did not touch internal/commands/init.go (the generated CLAUDE.md) — happy to add a line there if you'd prefer.

🤖 Generated with Claude Code

@arghhhhh arghhhhh force-pushed the feat/screenshot-opaque branch 2 times, most recently from 33ab64a to efc643a Compare May 29, 2026 20:49
Many TD shaders write fragColor with alpha=0 (e.g. atmospheric/sky
shaders that use the alpha channel for compositing flags, or simply
omit it). The captured PNG is technically correct but most viewers
composite RGBA over white when alpha=0, producing a blank image and
hiding the actual RGB content. TD's own node-viewer thumbnail ignores
alpha and shows RGB directly, so the disk capture doesn't match what
the artist sees in the network.

--opaque forces alpha=255 on every pixel of the returned PNG (Go-side,
no handler changes), giving viewers and downstream tooling RGB that
matches the in-network thumbnail. RGB channels are preserved as-is;
no premultiplied-alpha unpacking.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@arghhhhh arghhhhh force-pushed the feat/screenshot-opaque branch from efc643a to 898d3f4 Compare June 24, 2026 17: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.

1 participant