SPB Git

spb/metrika Public

Stata-class statistics, GPU-accelerated by Apple Silicon. Native Swift — no Electron, no Python runtime, no compromises.

Swift 92.4% HTML 3.3% R 3% Shell 1.3%
1.5 KB · 59 lines
Raw Blame History
1//2//  PointRenderer.metal3//  Metrika4//5//  Author:  Simon-Pierre Boucher6//  Contact: contact@spboucher.ai7//  Copyright © 2026 Simon-Pierre Boucher. All rights reserved.8//9//  Instanced point-sprite renderer for large scatter plots (CLAUDE.md §7:10//  custom MTKView renderer past the Swift Charts threshold). One packed11//  12-byte vertex per observation; the fragment stage rounds sprites.12//1314#include <metal_stdlib>15using namespace metal;1617struct PackedPoint {18    packed_float2 position;   // data coordinates19    uchar4 color;20};2122struct Uniforms {23    float2 center;            // data-space center of the viewport24    float2 scale;             // data → clip scaling (zoom × aspect)25    float pointSize;26};2728struct VertexOut {29    float4 position [[position]];30    float pointSize [[point_size]];31    float4 color;32};3334vertex VertexOut scatterVertex(35    uint vertexID [[vertex_id]],36    const device PackedPoint *points [[buffer(0)]],37    constant Uniforms &uniforms [[buffer(1)]]38) {39    PackedPoint point = points[vertexID];40    float2 clip = (float2(point.position) - uniforms.center) * uniforms.scale;4142    VertexOut out;43    out.position = float4(clip, 0.0, 1.0);44    out.pointSize = uniforms.pointSize;45    out.color = float4(point.color) / 255.0;46    return out;47}4849fragment float4 scatterFragment(50    VertexOut in [[stage_in]],51    float2 pointCoord [[point_coord]]52) {53    float2 offset = pointCoord - 0.5;54    if (dot(offset, offset) > 0.25) {55        discard_fragment();56    }57    return in.color;58}59