From 9bd77e54943d954291b5faef287ccca5dcebd7a4 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 00:15:15 -0300 Subject: examples: micscope and spheres come home, as they were, building Both lived outside any repository, beside sketchbook, with manifests that pointed at ../01-drat-meout/lib/sketchbook, which no longer exists. They are copied into examples/micscope and examples/spheres (their sources, shaders, tests, test material and web icons; not their caches, builds, packages, state files or .gitignore, which the root's covers), their manifests depend on "../.." as the other examples do, and their READMEs link sketchbook there. Nothing else changed: both build against today's library and pass their own zig build test (micscope 62/62 steps, 11/11 tests, its transport, record, render and tuner scripts; spheres 75/75 steps, 3/3 tests, its play script). The originals are untouched. micscope's test/reference.flac (3.7 MiB, CC BY-SA 3.0, credited in its test/README.md) is the rendering reference its render script opens. The README lists both examples. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- examples/micscope/shaders/spectrogram.frag | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 examples/micscope/shaders/spectrogram.frag (limited to 'examples/micscope/shaders/spectrogram.frag') diff --git a/examples/micscope/shaders/spectrogram.frag b/examples/micscope/shaders/spectrogram.frag new file mode 100644 index 0000000..9cb5e3d --- /dev/null +++ b/examples/micscope/shaders/spectrogram.frag @@ -0,0 +1,45 @@ +#version 450 +#extension GL_GOOGLE_include_directive : require +// The spectrogram (spectrogram.comp): time across, as the waveform above +// it, log frequency up, each level through a heat gradient (inferno: +// black, violet, red, orange, pale yellow), with the playhead. +layout(location = 0) out vec4 out_color; + +#include "SpectrogramView.glsl" + +layout(set = 2, binding = 0) readonly buffer Levels { float levels[]; }; + +// Match layouts.zig and spectrogram.comp. +const uint MAX_COLUMNS = 2048; +const float NO_TAPE = 1000.0; + +// Matplotlib's inferno, as a polynomial fit (Matt Zucker's, CC0). +vec3 inferno(float t) { + const vec3 c0 = vec3(0.0002189403691192265, 0.001651004631001012, -0.01948089843709184); + const vec3 c1 = vec3(0.1065134194856116, 0.5639564367884091, 3.932712388889277); + const vec3 c2 = vec3(11.60249308247187, -3.972853965665698, -15.9423941062914); + const vec3 c3 = vec3(-41.70399613139459, 17.43639888205313, 44.35414519872813); + const vec3 c4 = vec3(77.162935699427, -33.40235894210092, -81.80730925738993); + const vec3 c5 = vec3(-71.31942824499214, 32.62606426397723, 73.20951985803202); + const vec3 c6 = vec3(25.13112622477341, -12.24266895238567, -23.07032500287172); + return clamp(c0 + t * (c1 + t * (c2 + t * (c3 + t * (c4 + t * (c5 + t * c6))))), 0.0, 1.0); +} + +void main() { + vec2 p = gl_FragCoord.xy; + uint row = uint(u.size.y - p.y); + uint x = uint(p.x); + float db = levels[row * MAX_COLUMNS + (x + u.scroll) % uint(u.size.x)]; + if (x + u.filled < uint(u.size.x)) db = NO_TAPE; + vec3 color = vec3(0.035, 0.03, 0.05); + if (db < NO_TAPE) { + float t = clamp((db - u.floor_db) / (u.ceil_db - u.floor_db), 0.0, 1.0); + // A touch of contrast: quiet stays dark, loud blooms. + color = inferno(pow(t, 1.3)); + } + if (u.playhead >= 0.0) { + float d = abs(p.x - u.playhead); + color = mix(color, vec3(1.0, 0.85, 0.3), clamp(1.5 - d, 0.0, 1.0) * 0.8); + } + out_color = vec4(color, 1.0); +} -- cgit v1.3