Skip to content

feat(renderer): add iSurfaceOffset and iWindowResolution shader uniforms#12153

Open
yabbal wants to merge 2 commits intoghostty-org:mainfrom
yabbal:feat/surface-position-uniforms
Open

feat(renderer): add iSurfaceOffset and iWindowResolution shader uniforms#12153
yabbal wants to merge 2 commits intoghostty-org:mainfrom
yabbal:feat/surface-position-uniforms

Conversation

@yabbal
Copy link
Copy Markdown

@yabbal yabbal commented Apr 6, 2026

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) with iResolution set 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 window
  • iWindowResolution (vec4) — .xyz = total window size in pixels (same convention as iResolution)

With these, shaders can compute window-global UVs:

vec2 globalUV = (fragCoord.xy + iSurfaceOffset.xy) / iWindowResolution.xy;

Changes

  • Shader interface: 2 new uniforms in shadertoy.zig + shadertoy_prefix.glsl
  • Renderer: new surface_offset / window_size fields, populated per-frame, with safe defaults (offset=0, window=surface size)
  • Message system: new surface_position message for thread-safe updates
  • Core Surface: new surfacePositionCallback for apprts to report position, with crash metadata
  • macOS (Swift): updateSurfacePosition() in SurfaceView_AppKit.swift — computes position via convert(bounds, to: nil), flips Y axis, converts to backing pixels. Called on every sizeDidChange and viewDidChangeBackingProperties
  • GTK: computes position via computeBounds relative to the root widget, scaled by getScaleFactor() to physical pixels. Called on every resize

Backward 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.


Reopened from #11981 (original was closed while fork was deleted).

@yabbal yabbal requested review from a team as code owners April 6, 2026 23:45
@ghostty-bot ghostty-bot Bot added the renderer label Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant