summaryrefslogtreecommitdiff
path: root/examples/spheres/shaders/advance.comp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/spheres/shaders/advance.comp')
-rw-r--r--examples/spheres/shaders/advance.comp32
1 files changed, 32 insertions, 0 deletions
diff --git a/examples/spheres/shaders/advance.comp b/examples/spheres/shaders/advance.comp
new file mode 100644
index 0000000..e1e8789
--- /dev/null
+++ b/examples/spheres/shaders/advance.comp
@@ -0,0 +1,32 @@
+#version 450
+#extension GL_GOOGLE_include_directive : require
+// After synth.comp: where the block's phases ended, wrapped, for the next
+// block to start from; and the voices and coupling it ended on, to glide
+// from. (The coupling pushes phases without moving them on, so the phases
+// need nothing from it.)
+layout(local_size_x = 1) in;
+
+#include "SynthParams.glsl"
+
+layout(set = 1, binding = 0) buffer Voices { vec4 voices[]; };
+layout(set = 1, binding = 1) buffer Phases { vec4 phases[]; };
+
+const float TAU = 6.28318530718;
+
+void main() {
+ float count = float(u.count);
+ for (int i = 0; i < 3; i++) {
+ vec4 from = voices[i];
+ vec4 to = voices[3 + i];
+ vec4 phase = phases[i];
+ float wc0 = TAU * from.x / u.rate;
+ float wc1 = TAU * to.x / u.rate;
+ // As synth.comp's glide at n = count.
+ float c = phase.x + 0.5 * (wc0 + wc1) * count;
+ float m = phase.y + 0.5 * (wc0 * from.y + wc1 * to.y) * count;
+ float fm = phase.z + (c - phase.x) + to.z / max(to.y, 1e-3) * (sin(m) - sin(phase.y));
+ phases[i] = vec4(mod(c, TAU), mod(m, TAU), mod(fm, TAU), 0.0);
+ voices[i] = to;
+ voices[6 + i] = voices[9 + i];
+ }
+}