Files
openchamber-android-native/third_party/mygo/internal/gpu/metal/shadereffect.metal
T
OpenChamber 6c0ee61750 feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
2026-11-18 13:22:59 +08:00

33 lines
1.8 KiB
Metal

// The tail of a shader's library (package ui/shader), after the head of
// effect.metal and the shader's code, which ends with shaderMain: Metal
// has no global variables, so a shader's uniforms (buffer 2) and images
// (textures 5 to 8) come to the fragment function, which passes them on.
// Instances with 1 in params.y are mask glyphs it fills, read from the
// mask atlas (texture 0). shaderMain reads what the shader reads of a
// quad of those one draw draws (DrawInstances) from the instance.
fragment PSOut shader_ps(VSOut v [[stage_in]], const device Inst *insts [[buffer(0)]],
constant float4 &globals [[buffer(1)]], constant Uniforms &uniforms [[buffer(2)]],
texture2d<float> T0 [[texture(5)]], texture2d<float> T1 [[texture(6)]],
texture2d<float> T2 [[texture(7)]], texture2d<float> T3 [[texture(8)]],
texture2d<float> clipTex [[texture(4)]], texture2d<float> maskTex [[texture(0)]],
sampler samp [[sampler(0)]]) {
Inst i = insts[v.inst];
Frame fr = frameOf(v, i);
if (i.params.y > 0.5f) {
// A mask glyph the shader fills (scene.EffectOp.Glyphs), as ps
// draws one, its paint the shader's color, its positions from
// the box's corner in i.grad.
float4 c = shaderMain(uniforms, T0, T1, T2, T3, v.p, float4(i.grad.xy, i.rect.zw), i);
float glyphCov = i.transform0.w > 0.5f ? localCoverage(v.p, i.rect, float4(0.0f), 1.0f, fr) : 1.0f;
float4 res = c *
(textCoverage(sampleLocal(maskTex, samp, v.tex, i.uv, i.transform0.w).r, unpremul(c), i.inner.x,
i.inner.y, i.radii) *
glyphCov * clipCoverage(v, i, clipTex, samp) * i.params.w);
return PSOut{res, res.aaaa};
}
float4 res = shaderMain(uniforms, T0, T1, T2, T3, v.p, i.rect, i) *
(localCoverage(v.p, i.rect, i.radii, i.transform0.w, fr) * clipCoverage(v, i, clipTex, samp) * i.params.w);
return PSOut{res, res.aaaa};
}