SPB Git

Repository Public

Labels.metal 5.3 KB 133 lines

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * PROJECT METADATA8 * -----------------------------------------------------------------------------9 * Project          : ORIX Cosmos10 * File             : Shaders/Labels.metal11 * Description      : Screen-space text labels drawn from the CoreText atlas12 *                    (red: glyph coverage, green: halo coverage), instanced,13 *                    premultiplied alpha.14 * Module           : Shaders15 * Repository       : https://git.spboucher.ai/orix-cosmos16 * Project Website  : https://www.orixlab.dev17 * Created          : 2026-11-2418 * Last Modified    : 2026-11-2419 *20 * =============================================================================21 * AUTHOR & PROFESSIONAL AFFILIATION22 * =============================================================================23 *24 * Author           : Simon-Pierre Boucher25 * Position         : Professor of Finance26 * Institution      : Université du Québec en Outaouais (UQO)27 * Department       : Département des sciences administratives28 * Organization     : SP Boucher29 *30 * Website          : https://spboucher.ai31 * Git              : https://git.spboucher.ai32 *33 * =============================================================================34 * OFFICIAL CONTACT DIRECTORY35 * =============================================================================36 *37 * General          : info@spboucher.ai38 * Professional     : contact@spboucher.ai39 * Direct           : simon@spboucher.ai40 * Research         : research@spboucher.ai41 * Development      : dev@spboucher.ai42 * Support          : support@spboucher.ai43 * Security/Admin   : admin@spboucher.ai44 * Notifications    : notifications@spboucher.ai45 *46 * Preferred Contact: support@spboucher.ai47 *48 * =============================================================================49 * COPYRIGHT & INTELLECTUAL PROPERTY50 * =============================================================================51 *52 * Copyright (c) 202653 * Simon-Pierre Boucher54 *55 * All rights reserved where applicable.56 *57 * This file is governed by the applicable project license,58 * copyright notices, institutional agreements and relevant law.59 *60 * Unless expressly authorized by the applicable license or61 * rights holder, copying, redistribution, sublicensing,62 * publication and commercial exploitation are not permitted.63 *64 * Existing third-party rights and notices remain unaffected.65 *66 * =============================================================================67 * CONFIDENTIALITY & SECURITY68 * =============================================================================69 *70 * Classification   : Public71 * Distribution     : Public repository; use is governed by the project license72 * Security Contact : admin@spboucher.ai73 *74 * Access to this source does not independently grant permission75 * to redistribute or disclose confidential materials.76 *77 * Do not embed credentials, private keys, access tokens,78 * certificates or confidential personal information.79 *80 * =============================================================================81 * LICENSE & MAINTENANCE82 * =============================================================================83 *84 * License          : None specified (no license file in this repository)85 * Maintainer       : Simon-Pierre Boucher86 * Technical Contact: dev@spboucher.ai87 *88 * =============================================================================89 * END OF SP BOUCHER SOURCE HEADER90 * =============================================================================91 */9293#include "CosmosShared.h"9495struct LabelIn {96    float4 rect [[attribute(0)]];    // x, y (top-left), width, height in full-image output pixels97    float4 uv [[attribute(1)]];      // u0, v0, u1, v1 in the atlas98    float4 color [[attribute(2)]];   // straight linear rgba99    float4 halo [[attribute(3)]];    // straight linear rgba100};101102struct LabelVaryings {103    float4 position [[position]];104    float2 uv;105    float4 color [[flat]];106    float4 halo [[flat]];107};108109vertex LabelVaryings label_vertex(LabelIn in [[stage_in]],110                                  uint vid [[vertex_id]],111                                  constant FrameUniforms &frame [[buffer(1)]]) {112    float2 corner = float2(float(vid & 1u), float((vid >> 1) & 1u));113    float2 px = in.rect.xy + corner * in.rect.zw;114    float2 ndc = float2(px.x * frame.viewport.z * 2.0f - 1.0f, 1.0f - px.y * frame.viewport.w * 2.0f);115    LabelVaryings out;116    out.position = cosmos_crop(frame, float4(ndc, 0.0f, 1.0f));117    out.uv = mix(in.uv.xy, in.uv.zw, corner);118    out.color = in.color;119    out.halo = in.halo;120    return out;121}122123fragment float4 label_fragment(LabelVaryings in [[stage_in]],124                               texture2d<float> atlas [[texture(0)]],125                               sampler atlasSampler [[sampler(0)]]) {126    float4 t = atlas.sample(atlasSampler, in.uv);127    float fill = t.r * in.color.a;128    float halo = t.g * in.halo.a;129    float alpha = fill + halo * (1.0f - fill);130    float3 premultiplied = in.color.rgb * fill + in.halo.rgb * halo * (1.0f - fill);131    return float4(premultiplied, alpha);132}133
Files main
Menu

Theme