shadertoy sound webgl
basic shadertoy oldskool webgl sound
by nabr
JavaScript
// pretty much shadertoy in old fashioned webgl1 days
// thx to IQ
// based on https://stackoverflow.com/a/34878873 gman!!!!
// update dont work in chrome anymore
// https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#webaudio
// please use firefox
// https://www.mozilla.org/en-US/firefox/
(() => {
"use strict";
// vertex shader source
const vs = `#version 300 es
in vec2 p;void main(){gl_Position = vec4(p, 0., 1.f);}`;
// fragment shader source
const fs = `#version 300 es
precision mediump float;
uniform float iTime;
layout(location = 0) out lowp vec4 fragColor;
// https://www.shadertoy.com/view/ldfSW2
// srtuss, 2014
//
// Writing this crude 303 emulation + some percussion was the first thing i tried with the new
// soundshader-feature. The values are all tweaked by ear.
// number of synthesized harmonics (tune for quality/preformance)
const float pi2 = 2.*(atan(1.)*4.);float dist(float s, float d){return clamp(s * d, -1.0, 1.0);}vec2 dist(vec2 s, float d){return clamp(s * d, -1.0, 1.0);}float quan(float s, float c){return floor(s / c) * c;}float _filter(float h, float cut, float res){cut -= 20.0;float df = max(h - cut, 0.0), df2 = abs(h - cut);return exp(-0.005 * df * df) * 0.5 + exp(df2 * df2 * -0.1) * 2.2;}float nse(float x){return fract(sin(x * 110.082) * 19871.8972);}float nse_slide(float x){float fl = floor(x);return mix(nse(fl), nse(fl + 1.0), smoothstep(0.0, 1.0, fract(x)));}float ntof(float n){return 440.0 * pow(2.0, (n - 69.0) / 12.0);}vec2 synth(float tseq, float t){vec2 v = vec2(0.0);float tnote = fract(tseq);float dr = 0.26;float amp = smoothstep(0.05, 0.0, abs(tnote - dr - 0.05) - dr) * exp(tnote * -1.0);float seqn = nse(floor(tseq));float n = 20.0 + floor(seqn * 38.0);float f = ntof(n);float sqr = smoothstep(0.0, 0.01, abs(mod(t * 9.0, 64.0) - 20.0) - 20.0);float base = f;float flt = exp(tnote * -1.5) * 50.0 + pow(cos(t * 1.0) * 0.5 + 0.5, 4.0) * 80.0 - 0.0;for(int i = 0; i < 256; i ++){float h =...