summaryrefslogtreecommitdiff
path: root/examples/spheres/src/layouts.zig
diff options
context:
space:
mode:
Diffstat (limited to 'examples/spheres/src/layouts.zig')
-rw-r--r--examples/spheres/src/layouts.zig163
1 files changed, 163 insertions, 0 deletions
diff --git a/examples/spheres/src/layouts.zig b/examples/spheres/src/layouts.zig
new file mode 100644
index 0000000..c282e16
--- /dev/null
+++ b/examples/spheres/src/layouts.zig
@@ -0,0 +1,163 @@
+//! What spheres' shaders read and write, as Zig structs: the only
+//! definition. The shaders include GLSL generated from the uniform blocks;
+//! storage layouts (std430) are mirrored by hand where noted. No imports.
+
+/// Copies of the system integrated side by side: system 0 is the one heard
+/// and drawn in full, the rest start a hair apart and show where it could
+/// have gone.
+pub const max_systems = 16384;
+pub const bodies = 3;
+/// Positions kept per body for the trail.
+pub const trail = 1024;
+/// The most samples synthesised in one frame.
+pub const max_block = 8192;
+/// The look-ahead (lookahead.comp): futures of system 0 integrated side by
+/// side, and snapshots kept of each, one every `chords.sample_dt`.
+pub const alternatives = 32;
+pub const horizon = 2400;
+
+/// One body of one system (std430: vec4).
+pub const Body = extern struct {
+ pos: [2]f32,
+ vel: [2]f32,
+};
+
+/// One voice's synthesis parameters (std430: vec4).
+pub const Voice = extern struct {
+ /// Hz.
+ carrier: f32,
+ /// Modulator over carrier frequency.
+ ratio: f32,
+ /// The modulation depth: PM's index; FM's deviation over the carrier;
+ /// AM's and the additive voice's brightness.
+ depth: f32,
+ amp: f32,
+};
+
+/// The voices buffer, in vec4s: what the synthesiser last used and what
+/// sim.comp set now, for the voices and the coupling between them.
+pub const voices_previous = 0;
+pub const voices_now = 3;
+/// Row i of the coupling: how much each voice's signal (x, y, z) pushes
+/// voice i's carrier phase. Only the closest pair couples.
+pub const coupling_previous = 6;
+pub const coupling_now = 9;
+pub const voices_len = 12;
+
+/// What sim.comp reports of system 0, for the CPU (std430).
+pub const Lead = extern struct {
+ bodies: [3]Body,
+ voices: [3]Voice,
+ /// Rows of the coupling, as in the voices buffer (w unused).
+ coupling: [3][4]f32,
+ /// Kinetic plus potential.
+ energy: f32,
+ /// Simulated time.
+ time: f32,
+ pad: [2]f32 = .{ 0, 0 },
+};
+
+pub const Mode = enum(u32) { sine, additive, am, ring, fm, pm };
+
+/// Where pitches snap; voices.glsl's `snap`. The uniforms carry it as a u32.
+pub const Scale = enum(u32) { free, pentatonic, diatonic, chromatic };
+
+/// sim.comp: one thread per system.
+pub const SimParams = extern struct {
+ systems: u32,
+ /// Substeps this frame, each `dt` (negative runs time backwards),
+ /// subdivided further where bodies pass close.
+ steps: u32,
+ dt: f32,
+ softening: f32,
+ masses: [4]f32,
+ /// Where system 0's positions go in the trail ring; past `trail`, none.
+ trail_head: u32,
+ quantize: u32,
+ /// The pitch at `speed_ref`, Hz.
+ base: f32,
+ speed_ref: f32,
+ /// Modulation depth at unit distance.
+ depth_scale: f32,
+ /// How hard the closest pair couples at unit distance.
+ couple_scale: f32,
+ /// A look-ahead snapshot, as its index plus one, or 0: system 0 sings
+ /// from it (a held chord) rather than from its own motion.
+ voice_source: u32 = 0,
+ /// Likewise: system 0 takes the snapshot's state before moving on.
+ adopt: u32 = 0,
+ /// Trail points this frame, by simulated time rather than by frame, so
+ /// a fast travel leaves as smooth a path as running does: after step
+ /// `trail_first` (1-based), then every `trail_every` steps, `trail_points`
+ /// of them, from slot `trail_head` on.
+ trail_points: u32 = 0,
+ trail_first: u32 = 1,
+ trail_every: u32 = 1,
+ pad0: u32 = 0,
+
+ pub const glsl = .{ .uniform = .{ .set = 2, .instance = "u" } };
+};
+
+/// lookahead.comp: alternatives `count` samples on from `first`; and
+/// rechord.comp: the chords of the first `count` snapshots again.
+pub const LookParams = extern struct {
+ alternatives: u32,
+ first: u32,
+ count: u32,
+ horizon: u32,
+ masses: [4]f32,
+ softening: f32,
+ quantize: u32,
+ base: f32,
+ speed_ref: f32,
+ depth_scale: f32,
+ couple_scale: f32,
+ sample_dt: f32,
+ pad: u32 = 0,
+
+ pub const glsl = .{ .uniform = .{ .set = 2, .instance = "u" } };
+};
+
+/// synth.comp: one thread per sample.
+pub const SynthParams = extern struct {
+ count: u32,
+ /// A `Mode`.
+ mode: u32,
+ rate: f32,
+ gain: f32,
+
+ pub const glsl = .{ .uniform = .{ .set = 2, .instance = "u" } };
+};
+
+/// The sky's camera and sprites (vertex uniforms).
+pub const SkyView = extern struct {
+ /// World point at the image's centre, and world units per pixel.
+ center: [2]f32,
+ size: [2]f32,
+ per_pixel: f32,
+ radius: f32,
+ alpha: f32,
+ first: u32,
+ count: u32,
+ /// Trail: where the newest point is, and how many are filled.
+ head: u32,
+ filled: u32,
+ /// Seconds, for what flows.
+ time: f32,
+ /// Trail segments longer than this (world units) are jumps, not motion
+ /// (system 0 stepping into a snapshot): not drawn.
+ gap: f32 = 1e9,
+ pad0: f32 = 0,
+ pad1: f32 = 0,
+ pad2: f32 = 0,
+
+ pub const glsl = .{ .uniform = .{ .set = 1, .instance = "u" } };
+};
+
+/// fade.frag: moves what is there `amount` of the way to `background`.
+pub const Fade = extern struct {
+ background: [3]f32,
+ amount: f32,
+
+ pub const glsl = .{ .uniform = .{ .set = 3, .instance = "u" } };
+};