feat(renderer): add iSurfaceOffset and iWindowResolution shader uniforms#12153
Open
yabbal wants to merge 2 commits intoghostty-org:mainfrom
Open
feat(renderer): add iSurfaceOffset and iWindowResolution shader uniforms#12153yabbal wants to merge 2 commits intoghostty-org:mainfrom
yabbal wants to merge 2 commits intoghostty-org:mainfrom
Conversation
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
Custom shaders currently have no way to know where their surface sits within the window. Each split gets its own coordinate space starting at
(0,0)withiResolutionset to its own dimensions. This makes it impossible to create effects that span the full window (gradients, vignettes, CRT curvature) — they get duplicated per split instead.This PR adds two new Shadertoy uniforms:
iSurfaceOffset(vec4) —.xy= pixel position of this surface's top-left corner within the windowiWindowResolution(vec4) —.xyz= total window size in pixels (same convention asiResolution)With these, shaders can compute window-global UVs:
Changes
shadertoy.zig+shadertoy_prefix.glslsurface_offset/window_sizefields, populated per-frame, with safe defaults (offset=0, window=surface size)surface_positionmessage for thread-safe updatessurfacePositionCallbackfor apprts to report position, with crash metadataupdateSurfacePosition()inSurfaceView_AppKit.swift— computes position viaconvert(bounds, to: nil), flips Y axis, converts to backing pixels. Called on everysizeDidChangeandviewDidChangeBackingPropertiescomputeBoundsrelative to the root widget, scaled bygetScaleFactor()to physical pixels. Called on every resizeBackward compatibility
Fully backward-compatible. Defaults (
offset=0,0,window_resolution=iResolution) mean existing shaders behave identically. No existing code paths are modified.Related
AI disclosure
I used Claude Code (Anthropic) to assist with developing this PR. I've reviewed and understand all the code.