├── assets ├── s0.air ├── s0.metallib ├── u0.json └── s0.metal ├── images ├── 03.png ├── 04.png ├── 06.png ├── 10.png ├── 11.png ├── 14.png ├── 15.png ├── 16.png ├── 17.png └── 18.png ├── example_6.js ├── example_16.js ├── example_17.js ├── example_15.js ├── example_14.js ├── example_3.js ├── example_4.js ├── src ├── counter.js ├── MSL.js ├── shaderManager.js ├── timingUtils.js ├── renderpass-functions.js ├── MSLGeneratorFactory.js └── MSL-composable-glsl-functions.js ├── example_18.js ├── example_11.js ├── example_10.js ├── README.md └── LICENSE /assets/s0.air: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mizt/MSL-Hydra-Synth/HEAD/assets/s0.air -------------------------------------------------------------------------------- /images/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mizt/MSL-Hydra-Synth/HEAD/images/03.png -------------------------------------------------------------------------------- /images/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mizt/MSL-Hydra-Synth/HEAD/images/04.png -------------------------------------------------------------------------------- /images/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mizt/MSL-Hydra-Synth/HEAD/images/06.png -------------------------------------------------------------------------------- /images/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mizt/MSL-Hydra-Synth/HEAD/images/10.png -------------------------------------------------------------------------------- /images/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mizt/MSL-Hydra-Synth/HEAD/images/11.png -------------------------------------------------------------------------------- /images/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mizt/MSL-Hydra-Synth/HEAD/images/14.png -------------------------------------------------------------------------------- /images/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mizt/MSL-Hydra-Synth/HEAD/images/15.png -------------------------------------------------------------------------------- /images/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mizt/MSL-Hydra-Synth/HEAD/images/16.png -------------------------------------------------------------------------------- /images/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mizt/MSL-Hydra-Synth/HEAD/images/17.png -------------------------------------------------------------------------------- /images/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mizt/MSL-Hydra-Synth/HEAD/images/18.png -------------------------------------------------------------------------------- /assets/s0.metallib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mizt/MSL-Hydra-Synth/HEAD/assets/s0.metallib -------------------------------------------------------------------------------- /example_6.js: -------------------------------------------------------------------------------- 1 | require("./src/MSL.js"); 2 | 3 | osc(5).add(noise(5, 2)).color(0, 0, 3).colorama(0.4).out() 4 | -------------------------------------------------------------------------------- /example_16.js: -------------------------------------------------------------------------------- 1 | require("./src/MSL.js"); 2 | 3 | osc(4, 0.1, 0.8).color(1.04,0, -1.1).rotate(0.30, 0.1).pixelate(2, 20).modulate(noise(2.5), () => 1.5 * Math.sin(0.08 * time)).out(o0) -------------------------------------------------------------------------------- /example_17.js: -------------------------------------------------------------------------------- 1 | require("./src/MSL.js"); 2 | 3 | pattern = () => osc(200, 0).kaleid(200).scale(1, 0.4) 4 | // 5 | pattern() 6 | .scrollX(0.1, 0.01) 7 | .mult(pattern()) 8 | .out() -------------------------------------------------------------------------------- /example_15.js: -------------------------------------------------------------------------------- 1 | require("./src/MSL.js"); 2 | 3 | osc(100, 0.01, 1.4) 4 | .rotate(0, 0.1) 5 | .mult(osc(10, 0.1).modulate(osc(10).rotate(0, -0.1), 1)) 6 | .color(2.83,0.91,0.39) 7 | .out(o0) -------------------------------------------------------------------------------- /example_14.js: -------------------------------------------------------------------------------- 1 | require("./src/MSL.js"); 2 | 3 | osc(20, 0.01, 1.1) 4 | .kaleid(5) 5 | .color(2.83,0.91,0.39) 6 | .rotate(0, 0.1) 7 | .modulate(o0, () => mouse.x * 0.0003) 8 | .scale(1.01) 9 | .out(o0) -------------------------------------------------------------------------------- /example_3.js: -------------------------------------------------------------------------------- 1 | require("./src/MSL.js"); 2 | 3 | osc(20, 0.03, 1.7).kaleid().mult(osc(20, 0.001, 0).rotate(1.58)).blend(o0, 0.94).modulateScale(osc(10, 0),-0.03).scale(0.8, () => (1.05 + 0.1 * Math.sin(0.05*time))).out(o0) -------------------------------------------------------------------------------- /example_4.js: -------------------------------------------------------------------------------- 1 | require("./src/MSL.js"); 2 | 3 | osc(8,-0.5, 1).color(-1.5, -1.5, -1.5).blend(o0).rotate(-0.5, -0.5).modulate(shape(4).rotate(0.5, 0.5).scale(2).repeatX(2, 2).modulate(o0, () => mouse.x * 0.0005).repeatY(2, 2)).out(o0) -------------------------------------------------------------------------------- /src/counter.js: -------------------------------------------------------------------------------- 1 | // singleton class that generates ids to use has unique variable names for variables 2 | // counter.js 3 | 4 | let value = 0 5 | 6 | module.exports = { 7 | increment: () => value++, 8 | get: () => value 9 | } 10 | -------------------------------------------------------------------------------- /example_18.js: -------------------------------------------------------------------------------- 1 | require("./src/MSL.js"); 2 | 3 | osc(6, 0, 0.8) 4 | .color(1.14, 0.6,.80) 5 | .rotate(0.92, 0.3) 6 | .pixelate(20, 10) 7 | .mult(osc(40, 0.03).thresh(0.4).rotate(0, -0.02)) 8 | .modulateRotate(osc(20, 0).thresh(0.3, 0.6), () => 0.1 + mouse.x * 0.002) 9 | .out(o0) -------------------------------------------------------------------------------- /example_11.js: -------------------------------------------------------------------------------- 1 | require("./src/MSL.js"); 2 | 3 | osc(10, 0.9, 300) 4 | .color(0.9, 0.7, 0.8) 5 | .diff( 6 | osc(45, 0.3, 100) 7 | .color(0.9, 0.9, 0.9) 8 | .rotate(0.18) 9 | .pixelate(12) 10 | .kaleid() 11 | ) 12 | .scrollX(10) 13 | .colorama() 14 | .luma() 15 | .repeatX(4) 16 | .repeatY(4) 17 | .modulate( 18 | osc(1, -0.9, 300) 19 | ) 20 | .scale(2) 21 | .out() -------------------------------------------------------------------------------- /assets/u0.json: -------------------------------------------------------------------------------- 1 | { 2 | "frequency_11": 20, 3 | "sync_12": 0.01, 4 | "offset_13": 1.1, 5 | "nSides_14": 5, 6 | "r_15": 2.83, 7 | "g_16": 0.91, 8 | "b_17": 0.39, 9 | "a_18": 1, 10 | "angle_19": 0, 11 | "speed_20": 0.1, 12 | "amount_21": "(() => mouse.x * 0.0003)", 13 | "amount_22": 1.01, 14 | "xMult_23": 1, 15 | "yMult_24": 1, 16 | "offsetX_25": 0.5, 17 | "offsetY_26": 0.5 18 | } -------------------------------------------------------------------------------- /example_10.js: -------------------------------------------------------------------------------- 1 | require("./src/MSL.js"); 2 | 3 | osc( 215, 0.1, 2 ) 4 | .modulate( 5 | osc( 2, -0.3, 100 ) 6 | .rotate(15) 7 | ) 8 | .mult( 9 | osc( 215, -0.1, 2) 10 | .pixelate( 50, 50 ) 11 | ) 12 | .color( 0.9, 0.0, 0.9 ) 13 | .modulate( 14 | osc( 6, -0.1 ) 15 | .rotate( 9 ) 16 | ) 17 | .add( 18 | osc( 10, -0.9, 900 ) 19 | .color(1,0,1) 20 | ) 21 | .mult( 22 | shape(900, 0.2, 1) 23 | .luma() 24 | .repeatX(2) 25 | .repeatY(2) 26 | .colorama(10) 27 | ) 28 | .modulate( 29 | osc( 9, -0.3, 900 ) 30 | .rotate( 6 ) 31 | ) 32 | .add( 33 | osc(4, 1, 90) 34 | .color(0.2,0,1) 35 | ) 36 | .out() -------------------------------------------------------------------------------- /src/MSL.js: -------------------------------------------------------------------------------- 1 | const BUILD = true; 2 | const DIR = "./assets/"; 3 | const OS = "macosx"; // macosx, iphoneos, iphonesimulator 4 | 5 | slider=(value,min,max)=>"slider("+value+","+min+","+max+")"; 6 | 7 | function stringifyWithFunctions(object) { 8 | return JSON.stringify(object,(k,v) => { 9 | if(typeof(v)==="function") return `(${v})`; 10 | return v; 11 | },"\t"); 12 | }; 13 | 14 | global["o0"] = { 15 | name:"args.o0", 16 | uniforms:{}, 17 | getTexture:function() {}, 18 | renderPasses:function(glsl) { 19 | require("fs").writeFileSync(DIR+"u0.json",stringifyWithFunctions(glsl[0].uniforms)); 20 | require("fs").writeFileSync(DIR+"s0.metal",glsl[0].frag); 21 | if(BUILD) { 22 | require("child_process").execSync("xcrun -sdk "+OS+" metal -c "+DIR+"s0.metal -o "+DIR+"s0.air; xcrun -sdk "+OS+" metallib "+DIR+"s0.air -o "+DIR+"s0.metallib"); 23 | } 24 | } 25 | }; 26 | 27 | for(let k=0; k<4; k++) { 28 | global["s"+k] = { 29 | name:"args.s"+k, 30 | uniforms:{}, 31 | getTexture:function() {}, 32 | }; 33 | } 34 | 35 | const gen = new (require('./MSLGeneratorFactory.js'))(o0) 36 | global.generator = gen 37 | Object.keys(gen.functions).forEach((key)=>{ 38 | global[key] = gen.functions[key]; 39 | }) 40 | 41 | module.exports = {} -------------------------------------------------------------------------------- /src/shaderManager.js: -------------------------------------------------------------------------------- 1 | // to do: 2 | // 1. how to handle multi-pass renders 3 | // 2. how to handle vertex shaders 4 | 5 | module.exports = function (defaultOutput) { 6 | 7 | var Frag = function (shaderString) { 8 | var obj = Object.create(Frag.prototype) 9 | obj.shaderString = ` 10 | void main () { 11 | vec2 st = gl_FragCoord.xy/resolution.xy; 12 | gl_FragColor = vec4(st, 1.0, 1.0); 13 | } 14 | ` 15 | if(shaderString) obj.shaderString = shaderString 16 | return obj 17 | } 18 | 19 | Frag.prototype.compile = function () { 20 | var frag = ` 21 | precision highp float; 22 | uniform float time; 23 | uniform vec2 resolution; 24 | varying vec2 uv; 25 | 26 | ${this.shaderString} 27 | ` 28 | return frag 29 | } 30 | 31 | Frag.prototype.out = function (_output) { 32 | var output = _output || defaultOutput 33 | var frag = this.compile() 34 | output.frag = frag 35 | var pass = { 36 | frag: frag, 37 | uniforms: output.uniforms 38 | } 39 | console.log('rendering', pass) 40 | var passes = [] 41 | passes.push(pass) 42 | output.renderPasses([pass]) 43 | // var uniformObj = {} 44 | // this.uniforms.forEach((uniform) => { uniformObj[uniform.name] = uniform.value }) 45 | // output.uniforms = Object.assign(output.uniforms, uniformObj) 46 | output.render() 47 | } 48 | 49 | return Frag 50 | } 51 | -------------------------------------------------------------------------------- /src/timingUtils.js: -------------------------------------------------------------------------------- 1 | // some utility functions for managing time within hydra 2 | // to do: add easing functions: https://github.com/bameyrick/js-easing-functions 3 | 4 | // accepts a sequence of values as an array 5 | const seq = (arr = []) => ({time, bpm}) => 6 | { 7 | let speed = arr.speed ? arr.speed : 1 8 | return arr[Math.floor(time * speed * (bpm / 60) % (arr.length))] 9 | } 10 | 11 | // base sin oscillation 12 | const sin = (amplitude = 1, period = 0.1, offset = 0, offsetTime = 0) => ({time, bpm}) => { 13 | return amplitude * Math.sin((time + offsetTime) * period * (bpm / 60)) + offset 14 | } 15 | 16 | // continuously increasing 17 | const ramp = (scale = 1, offset = 0) => ({time, bpm}) => (time * scale + offset) 18 | 19 | // Utility functions and variables for managing fade in and outs: 20 | // creates a set of variables to store state. 21 | // usage: osc(f0(10, 100)).out() , where there variables are: minimum, maximum, and multiple in time 22 | // call fadeIn(0) to fade in all instances of f0, and fadeOut(0) to fadeOut 23 | function createFades (numFades) { 24 | // variables containing current state of fade 25 | const gain = Array(numFades).fill().map(() => ({ progress: 0, dir: 1, mult: 1})) 26 | 27 | // fade function to use as parameter 28 | const fade = (i) => (min = 0, max = 10, mult = 1) => () => { 29 | // console.log("gain", gain) 30 | gain[i].progress++ 31 | if(gain[i].dir > 0) { 32 | return Math.min(max, min + gain[i].progress * mult * gain[i].mult) 33 | } else { 34 | return Math.max(min, max - gain[i].progress * mult * gain[i].mult) 35 | } 36 | } 37 | 38 | // to do: put this code somewhere else 39 | gain.forEach((gain, index) => { 40 | global['f'+index] = fade(index) 41 | }) 42 | 43 | global.fadeIn = (index, _mult) => { 44 | gain[index] = { 45 | progress: 0, dir: 1, mult: _mult ? _mult : 1 46 | } 47 | } 48 | // 49 | global.fadeOut = (index, _mult) => { 50 | gain[index] = { 51 | progress: 0, dir: -1, mult: _mult ? _mult : 1 52 | } 53 | } 54 | } 55 | 56 | module.exports = { 57 | seq: seq, 58 | sin: sin, 59 | ramp: ramp, 60 | createFades: createFades 61 | } 62 | -------------------------------------------------------------------------------- /src/renderpass-functions.js: -------------------------------------------------------------------------------- 1 | // to add: ripple: https://www.shadertoy.com/view/4djGzz 2 | // mask 3 | // convolution 4 | // basic sdf shapes 5 | // repeat 6 | // iq color palletes 7 | 8 | module.exports = { 9 | _convolution: { 10 | type: 'renderpass_util', 11 | glsl: ` 12 | float kernel [9]; 13 | 14 | vec4 _convolution (vec2 uv, float[9] _kernel, float kernelWeight) { 15 | vec2 st = uv/resolution.xy; 16 | vec2 onePixel = vec2(4.0, 4.0) / resolution.xy; 17 | // vec2 onePixel = vec2(1.0, 1.0); 18 | vec4 colorSum = 19 | texture2D(prevBuffer, st + onePixel * vec2(-1, -1)) * _kernel[0] + 20 | texture2D(prevBuffer, st + onePixel * vec2( 0, -1)) * _kernel[1] + 21 | texture2D(prevBuffer, st + onePixel * vec2( 1, -1)) * _kernel[2] + 22 | texture2D(prevBuffer, st + onePixel * vec2(-1, 0)) * _kernel[3] + 23 | texture2D(prevBuffer, st + onePixel * vec2( 0, 0)) * _kernel[4] + 24 | texture2D(prevBuffer, st + onePixel * vec2( 1, 0)) * _kernel[5] + 25 | texture2D(prevBuffer, st + onePixel * vec2(-1, 1)) * _kernel[6] + 26 | texture2D(prevBuffer, st + onePixel * vec2( 0, 1)) * _kernel[7] + 27 | texture2D(prevBuffer, st + onePixel * vec2( 1, 1)) * _kernel[8] ; 28 | colorSum /= kernelWeight; 29 | return colorSum; 30 | } 31 | ` 32 | }, 33 | rgbShift: { 34 | type: 'renderpass', 35 | glsl: ` 36 | 37 | void main() { 38 | vec2 p = st; 39 | vec4 shift = vec4(-0.01, 0.02, 0.03, -0.04); 40 | vec2 rs = vec2(shift.x,-shift.y); 41 | vec2 gs = vec2(shift.y,-shift.z); 42 | vec2 bs = vec2(shift.z,-shift.x); 43 | 44 | float r = texture2D(prevBuffer, p+rs, 0.0).x; 45 | float g = texture2D(prevBuffer, p+gs, 0.0).y; 46 | float b = texture2D(prevBuffer, p+bs, 0.0).z; 47 | } 48 | ` 49 | }, 50 | edges: { 51 | type: 'renderpass', 52 | glsl: ` 53 | void main () { 54 | // kernel[0] = -0.125; kernel[1] = -0.125; kernel[2] = -0.125; 55 | // kernel[3] = -0.125; kernel[4] = 1.0; kernel[5] = -0.125; 56 | // kernel[6] = -0.125; kernel[7] = -0.125; kernel[8] = -0.125; 57 | 58 | // blur 59 | kernel[0] = 0.0; kernel[1] = 1.0; kernel[2] = 0.0; 60 | kernel[3] = 1.0; kernel[4] = 1.0; kernel[5] = 1.0; 61 | kernel[6] = 0.0; kernel[7] = 1.0; kernel[8] = 0.0; 62 | 63 | kernel[0] = 5.0; kernel[1] = -0.0; kernel[2] = -0.0; 64 | kernel[3] = 0.0; kernel[4] = 0.0; kernel[5] = 0.0; 65 | kernel[6] = -0.0; kernel[7] = -0.0; kernel[8] = -5.0; 66 | 67 | vec4 sum = _convolution( gl_FragCoord.xy, kernel, 10.0); 68 | gl_FragColor = clamp(sum , vec4(0.0), vec4(1.0)); 69 | // vec2 st = gl_FragCoord.xy/resolution.xy; 70 | // vec4 col = texture2D(prevBuffer, fract(st)); 71 | // gl_FragColor = vec4(st, 1.0, 1.0); 72 | } 73 | ` 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### MSL-Hydra-Synth 2 | 3 | Export [ojack](https://github.com/ojack) / [hydra-synth](https://github.com/ojack/hydra-synth) as Metal shader (WIP). 4 | 5 | ### Note 6 | 7 | * Source buffer is not supported. 8 | * Number of output buffers available is currently one. 9 | 10 | ### Architecture settings 11 | 12 | * `const OS = "macosx";` 13 | * `const OS = "iphoneos";` 14 | * `const OS = "iphonesimulator";` 15 | 16 | in `MSL.js` 17 | 18 | ### Build 19 | 20 | $node example_11.js 21 | 22 | The following two files are export. 23 | 24 | * ./assets/u0.json 25 | * ./assets/s0.metal 26 | 27 | ### Build MSL 28 | 29 | macosx 30 | 31 | $ cd ./assets 32 | $ xcrun -sdk macosx metal -c s0.metal -o s0.air; xcrun -sdk macosx metallib s0.air -o s0.metallib 33 | 34 | iphoneos 35 | 36 | $ cd ./assets 37 | $ xcrun -sdk iphoneos metal -c s0.metal -o s0.air; xcrun -sdk iphoneos metallib s0.air -o s0.metallib 38 | 39 | iphonesimulator 40 | 41 | $ cd ./assets 42 | $ xcrun -sdk iphonesimulator metal -c s0.metal -o s0.air; xcrun -sdk iphonesimulator metallib s0.air -o s0.metallib 43 | 44 | 45 | ### Play 46 | 47 | [Hydra-Synth-Player](https://github.com/mizt/MSL-Hydra-Synth-Player) 48 | 49 | 50 | ### Test 51 | 52 | [example\_3](https://hydra.ojack.xyz/?sketch_id=example_3) 53 | 54 | ![](./images/03.png "") 55 | 56 | by Olivia Jack 57 | 58 | osc(20, 0.03, 1.7).kaleid().mult(osc(20, 0.001, 0).rotate(1.58)).blend(o0, 0.94).modulateScale(osc(10, 0),-0.03).scale(0.8, () => (1.05 + 0.1 * Math.sin(0.05*time))).out(o0) 59 | 60 | [example\_4](https://hydra.ojack.xyz/?sketch_id=example_4) 61 | 62 | ![](./images/04.png "") 63 | 64 | by Nelson Vera 65 | twitter: @nel\_sonologia 66 | 67 | osc(8,-0.5, 1).color(-1.5, -1.5, -1.5).blend(o0).rotate(-0.5, -0.5).modulate(shape(4).rotate(0.5, 0.5).scale(2).repeatX(2, 2).modulate(o0, () => mouse.x * 0.0005).repeatY(2, 2)).out(o0) 68 | 69 | [example\_6](https://hydra.ojack.xyz/?sketch_id=example_6) 70 | 71 | ![](./images/06.png "") 72 | 73 | by Débora Falleiros Gonzales 74 | https://www.gonzalesdebora.com/ 75 | 76 | osc(5).add(noise(5, 2)).color(0, 0, 3).colorama(0.4).out() 77 | 78 | [example\_10](https://hydra.ojack.xyz/?sketch_id=example_10) 79 | 80 | ![](./images/10.png "") 81 | 82 | by Zach Krall 83 | http://zachkrall.online/ 84 | 85 | osc( 215, 0.1, 2 ) 86 | .modulate( 87 | osc( 2, -0.3, 100 ) 88 | .rotate(15) 89 | ) 90 | .mult( 91 | osc( 215, -0.1, 2) 92 | .pixelate( 50, 50 ) 93 | ) 94 | .color( 0.9, 0.0, 0.9 ) 95 | .modulate( 96 | osc( 6, -0.1 ) 97 | .rotate( 9 ) 98 | ) 99 | .add( 100 | osc( 10, -0.9, 900 ) 101 | .color(1,0,1) 102 | ) 103 | .mult( 104 | shape(900, 0.2, 1) 105 | .luma() 106 | .repeatX(2) 107 | .repeatY(2) 108 | .colorama(10) 109 | ) 110 | .modulate( 111 | osc( 9, -0.3, 900 ) 112 | .rotate( 6 ) 113 | ) 114 | .add( 115 | osc(4, 1, 90) 116 | .color(0.2,0,1) 117 | ) 118 | .out() 119 | 120 | [example\_11](https://hydra.ojack.xyz/?sketch_id=example_11) 121 | 122 | ![](./images/11.png "") 123 | 124 | by Zach Krall 125 | http://zachkrall.online/ 126 | 127 | osc(10, 0.9, 300) 128 | .color(0.9, 0.7, 0.8) 129 | .diff( 130 | osc(45, 0.3, 100) 131 | .color(0.9, 0.9, 0.9) 132 | .rotate(0.18) 133 | .pixelate(12) 134 | .kaleid() 135 | ) 136 | .scrollX(10) 137 | .colorama() 138 | .luma() 139 | .repeatX(4) 140 | .repeatY(4) 141 | .modulate( 142 | osc(1, -0.9, 300) 143 | ) 144 | .scale(2) 145 | .out() 146 | 147 | [example\_14](https://hydra.ojack.xyz/?sketch_id=example_14) 148 | 149 | ![](./images/14.png "") 150 | 151 | by Olivia Jack 152 | @\_ojack\_ 153 | 154 | osc(20, 0.01, 1.1) 155 | .kaleid(5) 156 | .color(2.83,0.91,0.39) 157 | .rotate(0, 0.1) 158 | .modulate(o0, () => mouse.x * 0.0003) 159 | .scale(1.01) 160 | .out(o0) 161 | 162 | 163 | [example\_15](https://hydra.ojack.xyz/?sketch_id=example_15) 164 | 165 | ![](./images/15.png "") 166 | 167 | by Olivia Jack 168 | https://ojack.github.io 169 | 170 | osc(100, 0.01, 1.4) 171 | .rotate(0, 0.1) 172 | .mult(osc(10, 0.1).modulate(osc(10).rotate(0, -0.1), 1)) 173 | .color(2.83,0.91,0.39) 174 | .out(o0) 175 | 176 | [example\_16](https://hydra.ojack.xyz/?sketch_id=example_16) 177 | 178 | ![](./images/16.png "") 179 | 180 | by Olivia Jack 181 | https://ojack.github.io 182 | 183 | osc(4, 0.1, 0.8).color(1.04,0, -1.1).rotate(0.30, 0.1).pixelate(2, 20).modulate(noise(2.5), () => 1.5 * Math.sin(0.08 * time)).out(o0) 184 | 185 | [example\_17](https://hydra.ojack.xyz/?sketch_id=example_17) 186 | 187 | ![](./images/17.png "") 188 | 189 | by Olivia Jack 190 | twitter: @_ojack_ 191 | 192 | pattern = () => osc(200, 0).kaleid(200).scale(1, 0.4) 193 | // 194 | pattern() 195 | .scrollX(0.1, 0.01) 196 | .mult(pattern()) 197 | .out() 198 | 199 | 200 | [example\_18](https://hydra.ojack.xyz/?sketch_id=example_18) 201 | 202 | ![](./images/18.png "") 203 | 204 | by Olivia Jack 205 | https://ojack.github.io 206 | 207 | osc(6, 0, 0.8) 208 | .color(1.14, 0.6,.80) 209 | .rotate(0.92, 0.3) 210 | .pixelate(20, 10) 211 | .mult(osc(40, 0.03).thresh(0.4).rotate(0, -0.02)) 212 | .modulateRotate(osc(20, 0).thresh(0.3, 0.6), () => 0.1 + mouse.x * 0.002) 213 | .out(o0) 214 | 215 | ### See also 216 | [https://note.mu/mizt/n/n5540821c2671](https://note.mu/mizt/n/n5540821c2671) 217 | -------------------------------------------------------------------------------- /src/MSLGeneratorFactory.js: -------------------------------------------------------------------------------- 1 | /* globals tex */ 2 | //const { seq, sin, ramp, createFades } = require('./timingUtils.js') 3 | const glslTransforms = require('./MSL-composable-glsl-functions.js') 4 | 5 | // in progress: implementing multiple renderpasses within a single 6 | // function string 7 | //const renderPassFunctions = require('./renderpass-functions.js') 8 | 9 | const counter = require('./counter.js') 10 | const shaderManager = require('./shaderManager.js') 11 | 12 | var Generator = function (param) { 13 | return Object.create(Generator.prototype) 14 | } 15 | 16 | // Functions that return a new transformation function based on the existing function chain as well 17 | // as the new function passed in. 18 | const compositionFunctions = { 19 | coord: existingF => newF => x => existingF(newF(x)), // coord transforms added onto beginning of existing function chain 20 | color: existingF => newF => x => newF(existingF(x)), // color transforms added onto end of existing function chain 21 | combine: existingF1 => existingF2 => newF => x => newF(existingF1(x))(existingF2(x)), // 22 | combineCoord: existingF1 => existingF2 => newF => x => existingF1(newF(x)(existingF2(x))) 23 | } 24 | // gl_FragColor = osc(modulate(osc(rotate(st, 10., 0.), 32., 0.1, 0.), st, 0.5), 199., 0.1, 0.); 25 | 26 | // hydra code: osc().rotate().color().repeat().out() 27 | // pseudo shader code: gl_FragColor = color(osc(rotate(repeat()))) 28 | 29 | // hydra code: osc().rotate().add(s0).repeat().out() 30 | // gl_FragColor = osc(rotate(repeat())) + tex(repeat()) 31 | 32 | // Parses javascript args to use in glsl 33 | function generateGlsl (inputs) { 34 | var str = '' 35 | inputs.forEach((input) => { 36 | str += ', ' + input.name 37 | }) 38 | return str 39 | } 40 | 41 | // when possible, reformats arguments to be the correct type 42 | // creates unique names for variables requiring a uniform to be passed in (i.e. a texture) 43 | // returns an object that contains the type and value of each argument 44 | // to do: add much more type checking, validation, and transformation to this part 45 | function formatArguments (userArgs, defaultArgs) { 46 | return defaultArgs.map((input, index) => { 47 | var typedArg = {} 48 | 49 | // if there is a user input at a certain index, create a uniform for this variable so that the value is passed in on each render pass 50 | // to do (possibly): check whether this is a function in order to only use uniforms when needed 51 | 52 | typedArg.isUniform = true 53 | 54 | if (userArgs.length > index) { 55 | // console.log("arg", userArgs[index]) 56 | typedArg.value = userArgs[index] 57 | // if argument passed in contains transform property, i.e. is of type generator, do not add uniform 58 | if (userArgs[index].transform) typedArg.isUniform = false 59 | 60 | if (typeof userArgs[index] === 'function') { 61 | typedArg.value = userArgs[index] 62 | } else if (userArgs[index].constructor === Array) { 63 | // console.log("is Array") 64 | typedArg.value = seq(userArgs[index]) 65 | } 66 | } else { 67 | // use default value for argument 68 | typedArg.value = input.default 69 | } 70 | // if input is a texture, set unique name for uniform 71 | if (input.type === 'texture') { 72 | 73 | //console.log(typedArg); 74 | // typedArg.tex = typedArg.value 75 | var x = typedArg.value 76 | typedArg.value = "" 77 | typedArg.name = x.name; 78 | } else { 79 | // if passing in a texture reference, when function asks for vec4, convert to vec4 80 | if (typedArg.value.getTexture && input.type === 'vec4') { 81 | 82 | var x = typedArg.value 83 | typedArg.value = src(x) 84 | typedArg.isUniform = false 85 | typedArg.name = x.name; 86 | } 87 | else { 88 | if(input.name=="time") { 89 | typedArg.name = input.name; 90 | } 91 | else if(input.name=="resolution") { 92 | typedArg.name = input.name; 93 | } 94 | else if(input.name=="tex") { 95 | typedArg.name = input.name; 96 | } 97 | else { 98 | if(typedArg.isUniform) { 99 | typedArg.name = input.name +"_"+ (11+counter.get()) 100 | counter.increment(); 101 | } 102 | else { 103 | typedArg.name = input.name; 104 | } 105 | } 106 | } 107 | } 108 | typedArg.type = input.type 109 | return typedArg 110 | }) 111 | } 112 | 113 | 114 | var GeneratorFactory = function (defaultOutput) { 115 | 116 | let self = this 117 | self.functions = {} 118 | 119 | // set global utility functions. to do: make global optional 120 | //global.sin = sin 121 | //global.ramp = ramp 122 | global.frag = shaderManager(defaultOutput) 123 | 124 | //createFades(6) 125 | // extend Array prototype 126 | Array.prototype.fast = function(speed) { 127 | // console.log("array fast", speed, this) 128 | this.speed = speed 129 | return this 130 | } 131 | 132 | Object.keys(glslTransforms).forEach((method) => { 133 | const transform = glslTransforms[method] 134 | 135 | // if type is a source, create a new global generator function that inherits from Generator object 136 | if (transform.type === 'src') { 137 | self.functions[method] = (...args) => { 138 | var obj = Object.create(Generator.prototype) 139 | obj.name = method 140 | const inputs = formatArguments(args, transform.inputs) 141 | obj.transform = (x) => { 142 | var glslString = `${method}(${x}` 143 | glslString += generateGlsl(inputs) 144 | glslString += ')' 145 | return glslString 146 | } 147 | obj.defaultOutput = defaultOutput 148 | obj.uniforms = [] 149 | inputs.forEach((input, index) => { 150 | if (input.isUniform) { 151 | obj.uniforms.push(input) 152 | } 153 | }) 154 | 155 | obj.passes = [] 156 | let pass = { 157 | transform: (x) => { 158 | var glslString = `${method}(${x}` 159 | glslString += generateGlsl(inputs) 160 | glslString += ')' 161 | return glslString 162 | }, 163 | uniforms: [] 164 | } 165 | inputs.forEach((input, index) => { 166 | if (input.isUniform) { 167 | pass.uniforms.push(input) 168 | } 169 | }) 170 | obj.passes.push(pass) 171 | return obj 172 | } 173 | } else { 174 | Generator.prototype[method] = function (...args) { 175 | const inputs = formatArguments(args, transform.inputs) 176 | 177 | if (transform.type === 'combine' || transform.type === 'combineCoord') { 178 | // composition function to be executed when all transforms have been added 179 | // c0 and c1 are two inputs.. (explain more) 180 | var f = (c0) => (c1) => { 181 | var glslString = `${method}(${c0}, ${c1}` 182 | glslString += generateGlsl(inputs.slice(1)) 183 | glslString += ')' 184 | return glslString 185 | } 186 | this.transform = compositionFunctions[glslTransforms[method].type](this.transform)(inputs[0].value.transform)(f) 187 | 188 | this.uniforms = this.uniforms.concat(inputs[0].value.uniforms) 189 | 190 | var pass = this.passes[this.passes.length - 1] 191 | pass.transform = this.transform 192 | pass.uniform + this.uniform 193 | } else { 194 | var f1 = (x) => { 195 | var glslString = `${method}(${x}` 196 | glslString += generateGlsl(inputs) 197 | glslString += ')' 198 | return glslString 199 | } 200 | this.transform = compositionFunctions[glslTransforms[method].type](this.transform)(f1) 201 | this.passes[this.passes.length - 1].transform = this.transform 202 | } 203 | 204 | inputs.forEach((input, index) => { 205 | if (input.isUniform) { 206 | this.uniforms.push(input) 207 | } 208 | }) 209 | this.passes[this.passes.length - 1].uniforms = this.uniforms 210 | return this 211 | } 212 | } 213 | }) 214 | } 215 | 216 | // 217 | // iterate through transform types and create a function for each 218 | // 219 | Generator.prototype.compile = function (pass) { 220 | // console.log("compiling", pass) 221 | var frag = `#pragma clang diagnostic push 222 | #pragma clang diagnostic ignored "-Wunused-variable" 223 | #include 224 | using namespace metal; 225 | 226 | #define vec2 float2 227 | #define vec3 float3 228 | #define vec4 float4 229 | #define ivec2 int2 230 | #define ivec3 int3 231 | #define ivec4 int4 232 | #define mat2 float2x2 233 | #define mat3 float3x3 234 | #define mat4 float4x4 235 | 236 | #define mod fmod 237 | #define atan 6.28318530718-atan2 238 | 239 | constexpr sampler _sampler(coord::normalized, address::clamp_to_edge, filter::nearest); 240 | 241 | struct VertInOut { 242 | float4 pos[[position]]; 243 | float2 texcoord[[user(texturecoord)]]; 244 | }; 245 | 246 | struct FragmentShaderArguments { 247 | device float *time[[id(0)]]; 248 | device float2 *resolution[[id(1)]]; 249 | device float2 *mouse[[id(2)]]; 250 | texture2d o0[[id(3)]]; 251 | texture2d o1[[id(4)]]; 252 | texture2d o2[[id(5)]]; 253 | texture2d o3[[id(6)]]; 254 | texture2d s0[[id(7)]]; 255 | texture2d s1[[id(8)]]; 256 | texture2d s2[[id(9)]]; 257 | texture2d s3[[id(10)]]; 258 | ${pass.uniforms.map((uniform) => { 259 | if(uniform.type=="texture") { 260 | return ''; 261 | } 262 | else if(uniform.name.indexOf("time")==0) { 263 | return ''; 264 | } 265 | else if(uniform.name.indexOf("resolution")==0) { 266 | return ''; 267 | } 268 | else { 269 | return ` device float *${uniform.name}[[id(${uniform.name.split("_")[1]})]]; 270 | ` 271 | } 272 | }).join('')+'};'} 273 | 274 | vertex VertInOut vertexShader(constant float4 *pos[[buffer(0)]],constant packed_float2 *texcoord[[buffer(1)]],uint vid[[vertex_id]]) { 275 | VertInOut outVert; 276 | outVert.pos = pos[vid]; 277 | outVert.texcoord = float2(texcoord[vid][0],1-texcoord[vid][1]); 278 | return outVert; 279 | } 280 | ${Object.values(glslTransforms).map((transform) => { 281 | return `${transform.glsl}` 282 | }).join('')} 283 | fragment float4 fragmentShader(VertInOut inFrag[[stage_in]],constant FragmentShaderArguments &args[[buffer(0)]]) { 284 | 285 | float time = args.time[0]; 286 | float2 resolution = args.resolution[0]; 287 | float2 mouse = args.mouse[0]; 288 | float2 gl_FragCoord = inFrag.pos.xy; 289 | vec4 c = vec4(1, 0, 0, 1); 290 | vec2 st = gl_FragCoord.xy/resolution.xy; 291 | ${pass.uniforms.map((uniform) => { 292 | if(uniform.type=="texture") { 293 | return ''; 294 | } 295 | else if(uniform.name.indexOf("time")==0) { 296 | return ''; 297 | } 298 | else if(uniform.name.indexOf("resolution")==0) { 299 | return ''; 300 | } 301 | else { 302 | return ` 303 | float ${uniform.name} = args.${uniform.name}[0];` 304 | } 305 | }).join('')} 306 | 307 | return ${pass.transform('st')}; 308 | } 309 | #pragma clang diagnostic pop` 310 | 311 | return frag 312 | } 313 | 314 | Generator.prototype.glsl = function (_output) { 315 | var output = _output || this.defaultOutput 316 | 317 | var passes = this.passes.map((pass) => { 318 | var uniforms = {} 319 | pass.uniforms.forEach((uniform) => { uniforms[uniform.name] = uniform.value }) 320 | if(pass.hasOwnProperty('transform')){ 321 | // console.log(" rendering pass", pass) 322 | 323 | return { 324 | frag: this.compile(pass), 325 | uniforms: Object.assign(output.uniforms, uniforms) 326 | } 327 | } else { 328 | // console.log(" not rendering pass", pass) 329 | return { 330 | frag: pass.frag, 331 | uniforms: Object.assign(output.uniforms, uniforms) 332 | } 333 | } 334 | }) 335 | return passes 336 | } 337 | 338 | 339 | 340 | Generator.prototype.out = function (_output) { 341 | // console.log('UNIFORMS', this.uniforms, output) 342 | var output = _output || this.defaultOutput 343 | 344 | var tmp = this.glsl(output); 345 | 346 | delete tmp[0].uniforms["args.o0"]; 347 | delete tmp[0].uniforms["args.o1"]; 348 | delete tmp[0].uniforms["args.s0"]; 349 | delete tmp[0].uniforms["args.s1"]; 350 | delete tmp[0].uniforms.time; 351 | delete tmp[0].uniforms.resolution; 352 | 353 | output.renderPasses(tmp); 354 | 355 | } 356 | 357 | module.exports = GeneratorFactory 358 | -------------------------------------------------------------------------------- /assets/s0.metal: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic push 2 | #pragma clang diagnostic ignored "-Wunused-variable" 3 | #include 4 | using namespace metal; 5 | 6 | #define vec2 float2 7 | #define vec3 float3 8 | #define vec4 float4 9 | #define ivec2 int2 10 | #define ivec3 int3 11 | #define ivec4 int4 12 | #define mat2 float2x2 13 | #define mat3 float3x3 14 | #define mat4 float4x4 15 | 16 | #define mod fmod 17 | #define atan 6.28318530718-atan2 18 | 19 | constexpr sampler _sampler(coord::normalized, address::clamp_to_edge, filter::nearest); 20 | 21 | struct VertInOut { 22 | float4 pos[[position]]; 23 | float2 texcoord[[user(texturecoord)]]; 24 | }; 25 | 26 | struct FragmentShaderArguments { 27 | device float *time[[id(0)]]; 28 | device float2 *resolution[[id(1)]]; 29 | device float2 *mouse[[id(2)]]; 30 | texture2d o0[[id(3)]]; 31 | texture2d o1[[id(4)]]; 32 | texture2d o2[[id(5)]]; 33 | texture2d o3[[id(6)]]; 34 | texture2d s0[[id(7)]]; 35 | texture2d s1[[id(8)]]; 36 | texture2d s2[[id(9)]]; 37 | texture2d s3[[id(10)]]; 38 | device float *frequency_11[[id(11)]]; 39 | device float *sync_12[[id(12)]]; 40 | device float *offset_13[[id(13)]]; 41 | device float *nSides_14[[id(14)]]; 42 | device float *r_15[[id(15)]]; 43 | device float *g_16[[id(16)]]; 44 | device float *b_17[[id(17)]]; 45 | device float *a_18[[id(18)]]; 46 | device float *angle_19[[id(19)]]; 47 | device float *speed_20[[id(20)]]; 48 | device float *amount_21[[id(21)]]; 49 | device float *amount_22[[id(22)]]; 50 | device float *xMult_23[[id(23)]]; 51 | device float *yMult_24[[id(24)]]; 52 | device float *offsetX_25[[id(25)]]; 53 | device float *offsetY_26[[id(26)]]; 54 | }; 55 | 56 | vertex VertInOut vertexShader(constant float4 *pos[[buffer(0)]],constant packed_float2 *texcoord[[buffer(1)]],uint vid[[vertex_id]]) { 57 | VertInOut outVert; 58 | outVert.pos = pos[vid]; 59 | outVert.texcoord = float2(texcoord[vid][0],1-texcoord[vid][1]); 60 | return outVert; 61 | } 62 | // Simplex 3D Noise 63 | // by Ian McEwan, Ashima Arts 64 | vec4 permute(vec4 x){return mod(((x*34.0)+1.0)*x, 289.0);} 65 | vec4 taylorInvSqrt(vec4 r){return 1.79284291400159 - 0.85373472095314 * r;} 66 | 67 | float _noise(vec3 v){ 68 | 69 | const vec2 C = vec2(1.0/6.0, 1.0/3.0) ; 70 | const vec4 D = vec4(0.0, 0.5, 1.0, 2.0); 71 | 72 | // First corner 73 | vec3 i = floor(v + dot(v, C.yyy) ); 74 | vec3 x0 = v - i + dot(i, C.xxx) ; 75 | 76 | // Other corners 77 | vec3 g = step(x0.yzx, x0.xyz); 78 | vec3 l = 1.0 - g; 79 | vec3 i1 = min( g.xyz, l.zxy ); 80 | vec3 i2 = max( g.xyz, l.zxy ); 81 | 82 | // x0 = x0 - 0. + 0.0 * C 83 | vec3 x1 = x0 - i1 + 1.0 * C.xxx; 84 | vec3 x2 = x0 - i2 + 2.0 * C.xxx; 85 | vec3 x3 = x0 - 1. + 3.0 * C.xxx; 86 | 87 | // Permutations 88 | i = mod(i, 289.0 ); 89 | vec4 p = permute( permute( permute( 90 | i.z + vec4(0.0, i1.z, i2.z, 1.0 )) 91 | + i.y + vec4(0.0, i1.y, i2.y, 1.0 )) 92 | + i.x + vec4(0.0, i1.x, i2.x, 1.0 )); 93 | 94 | // Gradients 95 | // ( N*N points uniformly over a square, mapped onto an octahedron.) 96 | float n_ = 1.0/7.0; // N=7 97 | vec3 ns = n_ * D.wyz - D.xzx; 98 | 99 | vec4 j = p - 49.0 * floor(p * ns.z *ns.z); // mod(p,N*N) 100 | 101 | vec4 x_ = floor(j * ns.z); 102 | vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N) 103 | 104 | vec4 x = x_ *ns.x + ns.yyyy; 105 | vec4 y = y_ *ns.x + ns.yyyy; 106 | vec4 h = 1.0 - abs(x) - abs(y); 107 | 108 | vec4 b0 = vec4( x.xy, y.xy ); 109 | vec4 b1 = vec4( x.zw, y.zw ); 110 | 111 | vec4 s0 = floor(b0)*2.0 + 1.0; 112 | vec4 s1 = floor(b1)*2.0 + 1.0; 113 | vec4 sh = -step(h, vec4(0.0)); 114 | 115 | vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ; 116 | vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ; 117 | 118 | vec3 p0 = vec3(a0.xy,h.x); 119 | vec3 p1 = vec3(a0.zw,h.y); 120 | vec3 p2 = vec3(a1.xy,h.z); 121 | vec3 p3 = vec3(a1.zw,h.w); 122 | 123 | //Normalise gradients 124 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 125 | p0 *= norm.x; 126 | p1 *= norm.y; 127 | p2 *= norm.z; 128 | p3 *= norm.w; 129 | 130 | // Mix final noise value 131 | vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0); 132 | m = m * m; 133 | return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1), 134 | dot(p2,x2), dot(p3,x3) ) ); 135 | } 136 | vec4 noise(vec2 st, float scale, float offset, float time){ 137 | return vec4(vec3(_noise(vec3(st*scale, offset*time))), 1.0); 138 | } 139 | vec4 voronoi(vec2 st, float scale, float speed, float blending, float time) { 140 | vec3 color = vec3(.0); 141 | 142 | // Scale 143 | st *= scale; 144 | 145 | // Tile the space 146 | vec2 i_st = floor(st); 147 | vec2 f_st = fract(st); 148 | 149 | float m_dist = 10.; // minimun distance 150 | vec2 m_point; // minimum point 151 | 152 | for (int j=-1; j<=1; j++ ) { 153 | for (int i=-1; i<=1; i++ ) { 154 | vec2 neighbor = vec2(float(i),float(j)); 155 | vec2 p = i_st + neighbor; 156 | vec2 point = fract(sin(vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3))))*43758.5453); 157 | point = 0.5 + 0.5*sin(time*speed + 6.2831*point); 158 | vec2 diff = neighbor + point - f_st; 159 | float dist = length(diff); 160 | 161 | if( dist < m_dist ) { 162 | m_dist = dist; 163 | m_point = point; 164 | } 165 | } 166 | } 167 | 168 | // Assign a color using the closest point position 169 | color += dot(m_point,vec2(.3,.6)); 170 | color *= 1.0 - blending*m_dist; 171 | return vec4(color, 1.0); 172 | } 173 | vec4 osc(vec2 _st, float freq, float sync, float offset, float time){ 174 | vec2 st = _st; 175 | float r = sin((st.x-offset/freq+time*sync)*freq)*0.5 + 0.5; 176 | float g = sin((st.x+time*sync)*freq)*0.5 + 0.5; 177 | float b = sin((st.x+offset/freq+time*sync)*freq)*0.5 + 0.5; 178 | return vec4(r, g, b, 1.0); 179 | } 180 | vec4 shape(vec2 _st, float sides, float radius, float smoothing){ 181 | vec2 st = _st * 2. - 1.; 182 | // Angle and radius from the current pixel 183 | float a = atan(st.x,st.y)+3.1416; 184 | float r = (2.*3.1416)/sides; 185 | float d = cos(floor(.5+a/r)*r-a)*length(st); 186 | return vec4(vec3(1.0-smoothstep(radius,radius + smoothing,d)), 1.0); 187 | } 188 | vec4 gradient(vec2 _st, float speed, float time) { 189 | return vec4(_st, sin(time*speed), 1.0); 190 | } 191 | vec4 src(vec2 _st, texture2d _tex){ 192 | return _tex.sample(_sampler,fract(_st)); 193 | } 194 | vec4 solid(vec2 uv, float _r, float _g, float _b, float _a){ 195 | return vec4(_r, _g, _b, _a); 196 | } 197 | vec2 rotate(vec2 st, float _angle, float speed, float time){ 198 | vec2 xy = st - vec2(0.5); 199 | float angle = _angle + speed *time; 200 | xy = mat2(cos(angle),-sin(angle), sin(angle),cos(angle))*xy; 201 | xy += 0.5; 202 | return xy; 203 | } 204 | vec2 scale(vec2 st, float amount, float xMult, float yMult, float offsetX, float offsetY){ 205 | vec2 xy = st - vec2(offsetX, offsetY); 206 | xy*=(1.0/vec2(amount*xMult, amount*yMult)); 207 | xy+=vec2(offsetX, offsetY); 208 | return xy; 209 | } 210 | vec2 pixelate(vec2 st, float pixelX, float pixelY){ 211 | vec2 xy = vec2(pixelX, pixelY); 212 | return (floor(st * xy) + 0.5)/xy; 213 | } 214 | vec4 posterize(vec4 c, float bins, float gamma){ 215 | vec4 c2 = pow(c, vec4(gamma)); 216 | c2 *= vec4(bins); 217 | c2 = floor(c2); 218 | c2/= vec4(bins); 219 | c2 = pow(c2, vec4(1.0/gamma)); 220 | return vec4(c2.xyz, c.a); 221 | } 222 | vec4 shift(vec4 c, float r, float g, float b, float a){ 223 | vec4 c2 = vec4(c); 224 | c2.r = fract(c2.r + r); 225 | c2.g = fract(c2.g + g); 226 | c2.b = fract(c2.b + b); 227 | c2.a = fract(c2.a + a); 228 | return vec4(c2.rgba); 229 | } 230 | vec2 repeat(vec2 _st, float repeatX, float repeatY, float offsetX, float offsetY){ 231 | vec2 st = _st * vec2(repeatX, repeatY); 232 | st.x += step(1., mod(st.y,2.0)) * offsetX; 233 | st.y += step(1., mod(st.x,2.0)) * offsetY; 234 | return fract(st); 235 | } 236 | vec2 modulateRepeat(vec2 _st, vec4 c1, float repeatX, float repeatY, float offsetX, float offsetY){ 237 | vec2 st = _st * vec2(repeatX, repeatY); 238 | st.x += step(1., mod(st.y,2.0)) + c1.r * offsetX; 239 | st.y += step(1., mod(st.x,2.0)) + c1.g * offsetY; 240 | return fract(st); 241 | } 242 | vec2 repeatX(vec2 _st, float reps, float offset){ 243 | vec2 st = _st * vec2(reps, 1.0); 244 | // float f = mod(_st.y,2.0); 245 | st.y += step(1., mod(st.x,2.0))* offset; 246 | return fract(st); 247 | } 248 | vec2 modulateRepeatX(vec2 _st, vec4 c1, float reps, float offset){ 249 | vec2 st = _st * vec2(reps, 1.0); 250 | // float f = mod(_st.y,2.0); 251 | st.y += step(1., mod(st.x,2.0)) + c1.r * offset; 252 | return fract(st); 253 | } 254 | vec2 repeatY(vec2 _st, float reps, float offset){ 255 | vec2 st = _st * vec2(1.0, reps); 256 | // float f = mod(_st.y,2.0); 257 | st.x += step(1., mod(st.y,2.0))* offset; 258 | return fract(st); 259 | } 260 | vec2 modulateRepeatY(vec2 _st, vec4 c1, float reps, float offset){ 261 | vec2 st = _st * vec2(reps, 1.0); 262 | // float f = mod(_st.y,2.0); 263 | st.x += step(1., mod(st.y,2.0)) + c1.r * offset; 264 | return fract(st); 265 | } 266 | vec2 kaleid(vec2 st, float nSides){ 267 | st -= 0.5; 268 | float r = length(st); 269 | float a = atan(st.y, st.x); 270 | float pi = 2.*3.1416; 271 | a = mod(a,pi/nSides); 272 | a = abs(a-pi/nSides/2.); 273 | return r*vec2(cos(a), sin(a)); 274 | } 275 | vec2 modulateKaleid(vec2 st, vec4 c1, float nSides){ 276 | st -= 0.5; 277 | float r = length(st); 278 | float a = atan(st.y, st.x); 279 | float pi = 2.*3.1416; 280 | a = mod(a,pi/nSides); 281 | a = abs(a-pi/nSides/2.); 282 | return (c1.r+r)*vec2(cos(a), sin(a)); 283 | } 284 | vec2 scrollX(vec2 st, float amount, float speed, float time){ 285 | st.x += amount + time*speed; 286 | return fract(st); 287 | } 288 | vec2 modulateScrollX(vec2 st, vec4 c1, float amount, float speed, float time){ 289 | st.x += c1.r*amount + time*speed; 290 | return fract(st); 291 | } 292 | vec2 scrollY(vec2 st, float amount, float speed, float time){ 293 | st.y += amount + time*speed; 294 | return fract(st); 295 | } 296 | vec2 modulateScrollY(vec2 st, vec4 c1, float amount, float speed, float time){ 297 | st.y += c1.r*amount + time*speed; 298 | return fract(st); 299 | } 300 | vec4 add(vec4 c0, vec4 c1, float amount){ 301 | return (c0+c1)*amount + c0*(1.0-amount); 302 | } 303 | vec4 layer(vec4 c0, vec4 c1){ 304 | return vec4(mix(c0.rgb, c1.rgb, c1.a), c0.a+c1.a); 305 | } 306 | vec4 blend(vec4 c0, vec4 c1, float amount){ 307 | return c0*(1.0-amount)+c1*amount; 308 | } 309 | vec4 mult(vec4 c0, vec4 c1, float amount){ 310 | return c0*(1.0-amount)+(c0*c1)*amount; 311 | } 312 | vec4 diff(vec4 c0, vec4 c1){ 313 | return vec4(abs(c0.rgb-c1.rgb), max(c0.a, c1.a)); 314 | } 315 | vec2 modulate(vec2 st, vec4 c1, float amount){ 316 | // return fract(st+(c1.xy-0.5)*amount); 317 | return st + c1.xy*amount; 318 | } 319 | vec2 modulateScale(vec2 st, vec4 c1, float multiple, float offset){ 320 | vec2 xy = st - vec2(0.5); 321 | xy*=(1.0/vec2(offset + multiple*c1.r, offset + multiple*c1.g)); 322 | xy+=vec2(0.5); 323 | return xy; 324 | } 325 | vec2 modulatePixelate(vec2 st, vec4 c1, float multiple, float offset){ 326 | vec2 xy = vec2(offset + c1.x*multiple, offset + c1.y*multiple); 327 | return (floor(st * xy) + 0.5)/xy; 328 | } 329 | vec2 modulateRotate(vec2 st, vec4 c1, float multiple, float offset){ 330 | vec2 xy = st - vec2(0.5); 331 | float angle = offset + c1.x * multiple; 332 | xy = mat2(cos(angle),-sin(angle), sin(angle),cos(angle))*xy; 333 | xy += 0.5; 334 | return xy; 335 | } 336 | vec2 modulateHue(vec2 st, vec4 c1, float amount, vec2 resolution){ 337 | return st + (vec2(c1.g - c1.r, c1.b - c1.g) * amount * 1.0/resolution.xy); 338 | } 339 | vec4 invert(vec4 c0, float amount){ 340 | return vec4((1.0-c0.rgb)*amount + c0.rgb*(1.0-amount), c0.a); 341 | } 342 | vec4 contrast(vec4 c0, float amount) { 343 | vec4 c = (c0-vec4(0.5))*vec4(amount) + vec4(0.5); 344 | return vec4(c.rgb, c0.a); 345 | } 346 | vec4 brightness(vec4 c0, float amount){ 347 | return vec4(c0.rgb + vec3(amount), c0.a); 348 | } 349 | float luminance(vec3 rgb){ 350 | const vec3 W = vec3(0.2125, 0.7154, 0.0721); 351 | return dot(rgb, W); 352 | }vec4 mask(vec4 c0, vec4 c1){ 353 | float a = luminance(c1.rgb); 354 | return vec4(c0.rgb*a, a); 355 | }vec4 luma(vec4 c0, float threshold, float tolerance){ 356 | float a = smoothstep(threshold-tolerance, threshold+tolerance, luminance(c0.rgb)); 357 | return vec4(c0.rgb*a, a); 358 | } 359 | vec4 thresh(vec4 c0, float threshold, float tolerance){ 360 | return vec4(vec3(smoothstep(threshold-tolerance, threshold+tolerance, luminance(c0.rgb))), c0.a); 361 | } 362 | vec4 color(vec4 c0, float _r, float _g, float _b, float _a){ 363 | vec4 c = vec4(_r, _g, _b, _a); 364 | vec4 pos = step(0.0, c); // detect whether negative 365 | 366 | // if > 0, return r * c0 367 | // if < 0 return (1.0-r) * c0 368 | return vec4(mix((1.0-c0)*abs(c), c*c0, pos)); 369 | } 370 | vec3 _rgbToHsv(vec3 c){ 371 | vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); 372 | vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); 373 | vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); 374 | float d = q.x - min(q.w, q.y); 375 | return vec3(abs(q.z+((d==0.0)?1.0:((q.w-q.y)/(6.0*d)))), (q.x==0.0)?3.402823466e+38:(d/q.x), q.x); 376 | } 377 | vec3 _hsvToRgb(vec3 c){ 378 | vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); 379 | vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); 380 | return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); 381 | } 382 | vec4 saturate(vec4 c0, float amount){ 383 | const vec3 W = vec3(0.2125, 0.7154, 0.0721); 384 | vec3 intensity = vec3(dot(c0.rgb, W)); 385 | return vec4(mix(intensity, c0.rgb, amount), c0.a); 386 | } 387 | vec4 hue(vec4 c0, float hue){ 388 | vec3 c = _rgbToHsv(c0.rgb); 389 | c.r += hue; 390 | // c.r = fract(c.r); 391 | return vec4(_hsvToRgb(c), c0.a); 392 | } 393 | vec4 colorama(vec4 c0, float amount){ 394 | vec3 c = _rgbToHsv(c0.rgb); 395 | c += vec3(amount); 396 | c = _hsvToRgb(c); 397 | c = fract(c); 398 | return vec4(c, c0.a); 399 | } 400 | 401 | fragment float4 fragmentShader(VertInOut inFrag[[stage_in]],constant FragmentShaderArguments &args[[buffer(0)]]) { 402 | 403 | float time = args.time[0]; 404 | float2 resolution = args.resolution[0]; 405 | float2 mouse = args.mouse[0]; 406 | float2 gl_FragCoord = inFrag.pos.xy; 407 | vec4 c = vec4(1, 0, 0, 1); 408 | vec2 st = gl_FragCoord.xy/resolution.xy; 409 | 410 | float frequency_11 = args.frequency_11[0]; 411 | float sync_12 = args.sync_12[0]; 412 | float offset_13 = args.offset_13[0]; 413 | float nSides_14 = args.nSides_14[0]; 414 | float r_15 = args.r_15[0]; 415 | float g_16 = args.g_16[0]; 416 | float b_17 = args.b_17[0]; 417 | float a_18 = args.a_18[0]; 418 | float angle_19 = args.angle_19[0]; 419 | float speed_20 = args.speed_20[0]; 420 | float amount_21 = args.amount_21[0]; 421 | float amount_22 = args.amount_22[0]; 422 | float xMult_23 = args.xMult_23[0]; 423 | float yMult_24 = args.yMult_24[0]; 424 | float offsetX_25 = args.offsetX_25[0]; 425 | float offsetY_26 = args.offsetY_26[0]; 426 | 427 | return color(osc(kaleid(rotate(modulate(scale(st, amount_22, xMult_23, yMult_24, offsetX_25, offsetY_26), src(scale(st, amount_22, xMult_23, yMult_24, offsetX_25, offsetY_26), args.o0), amount_21), angle_19, speed_20, time), nSides_14), frequency_11, sync_12, offset_13, time), r_15, g_16, b_17, a_18); 428 | } 429 | #pragma clang diagnostic pop -------------------------------------------------------------------------------- /src/MSL-composable-glsl-functions.js: -------------------------------------------------------------------------------- 1 | // to add: ripple: https://www.shadertoy.com/view/4djGzz 2 | // mask 3 | // convolution 4 | // basic sdf shapes 5 | // repeat 6 | // iq color palletes 7 | 8 | module.exports = { 9 | 10 | _noise: { 11 | type: 'util', 12 | glsl: `// Simplex 3D Noise 13 | // by Ian McEwan, Ashima Arts 14 | vec4 permute(vec4 x){return mod(((x*34.0)+1.0)*x, 289.0);} 15 | vec4 taylorInvSqrt(vec4 r){return 1.79284291400159 - 0.85373472095314 * r;} 16 | 17 | float _noise(vec3 v){ 18 | 19 | const vec2 C = vec2(1.0/6.0, 1.0/3.0) ; 20 | const vec4 D = vec4(0.0, 0.5, 1.0, 2.0); 21 | 22 | // First corner 23 | vec3 i = floor(v + dot(v, C.yyy) ); 24 | vec3 x0 = v - i + dot(i, C.xxx) ; 25 | 26 | // Other corners 27 | vec3 g = step(x0.yzx, x0.xyz); 28 | vec3 l = 1.0 - g; 29 | vec3 i1 = min( g.xyz, l.zxy ); 30 | vec3 i2 = max( g.xyz, l.zxy ); 31 | 32 | // x0 = x0 - 0. + 0.0 * C 33 | vec3 x1 = x0 - i1 + 1.0 * C.xxx; 34 | vec3 x2 = x0 - i2 + 2.0 * C.xxx; 35 | vec3 x3 = x0 - 1. + 3.0 * C.xxx; 36 | 37 | // Permutations 38 | i = mod(i, 289.0 ); 39 | vec4 p = permute( permute( permute( 40 | i.z + vec4(0.0, i1.z, i2.z, 1.0 )) 41 | + i.y + vec4(0.0, i1.y, i2.y, 1.0 )) 42 | + i.x + vec4(0.0, i1.x, i2.x, 1.0 )); 43 | 44 | // Gradients 45 | // ( N*N points uniformly over a square, mapped onto an octahedron.) 46 | float n_ = 1.0/7.0; // N=7 47 | vec3 ns = n_ * D.wyz - D.xzx; 48 | 49 | vec4 j = p - 49.0 * floor(p * ns.z *ns.z); // mod(p,N*N) 50 | 51 | vec4 x_ = floor(j * ns.z); 52 | vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N) 53 | 54 | vec4 x = x_ *ns.x + ns.yyyy; 55 | vec4 y = y_ *ns.x + ns.yyyy; 56 | vec4 h = 1.0 - abs(x) - abs(y); 57 | 58 | vec4 b0 = vec4( x.xy, y.xy ); 59 | vec4 b1 = vec4( x.zw, y.zw ); 60 | 61 | vec4 s0 = floor(b0)*2.0 + 1.0; 62 | vec4 s1 = floor(b1)*2.0 + 1.0; 63 | vec4 sh = -step(h, vec4(0.0)); 64 | 65 | vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ; 66 | vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ; 67 | 68 | vec3 p0 = vec3(a0.xy,h.x); 69 | vec3 p1 = vec3(a0.zw,h.y); 70 | vec3 p2 = vec3(a1.xy,h.z); 71 | vec3 p3 = vec3(a1.zw,h.w); 72 | 73 | //Normalise gradients 74 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 75 | p0 *= norm.x; 76 | p1 *= norm.y; 77 | p2 *= norm.z; 78 | p3 *= norm.w; 79 | 80 | // Mix final noise value 81 | vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0); 82 | m = m * m; 83 | return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1), 84 | dot(p2,x2), dot(p3,x3) ) ); 85 | } 86 | ` 87 | }, 88 | noise: { 89 | type: 'src', 90 | inputs: [ 91 | { 92 | type: 'float', 93 | name: 'scale', 94 | default: 10 95 | }, 96 | { 97 | type: 'float', 98 | name: 'offset', 99 | default : 0.1 100 | }, 101 | { 102 | name: 'time', 103 | type: 'float', 104 | default: 'time' 105 | } 106 | ], 107 | glsl: `vec4 noise(vec2 st, float scale, float offset, float time){ 108 | return vec4(vec3(_noise(vec3(st*scale, offset*time))), 1.0); 109 | } 110 | ` 111 | }, 112 | voronoi: { 113 | type: 'src', 114 | inputs: [ 115 | { 116 | type: 'float', 117 | name: 'scale', 118 | default: 5 119 | }, 120 | { 121 | type: 'float', 122 | name: 'speed', 123 | default : 0.3 124 | }, 125 | { 126 | type: 'float', 127 | name: 'blending', 128 | default : 0.3 129 | }, 130 | { 131 | name: 'time', 132 | type: 'float', 133 | default: 'time' 134 | } 135 | ], 136 | notes: 'from https://thebookofshaders.com/edit.php#12/vorono-01.frag, https://www.shadertoy.com/view/ldB3zc', 137 | glsl: `vec4 voronoi(vec2 st, float scale, float speed, float blending, float time) { 138 | vec3 color = vec3(.0); 139 | 140 | // Scale 141 | st *= scale; 142 | 143 | // Tile the space 144 | vec2 i_st = floor(st); 145 | vec2 f_st = fract(st); 146 | 147 | float m_dist = 10.; // minimun distance 148 | vec2 m_point; // minimum point 149 | 150 | for (int j=-1; j<=1; j++ ) { 151 | for (int i=-1; i<=1; i++ ) { 152 | vec2 neighbor = vec2(float(i),float(j)); 153 | vec2 p = i_st + neighbor; 154 | vec2 point = fract(sin(vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3))))*43758.5453); 155 | point = 0.5 + 0.5*sin(time*speed + 6.2831*point); 156 | vec2 diff = neighbor + point - f_st; 157 | float dist = length(diff); 158 | 159 | if( dist < m_dist ) { 160 | m_dist = dist; 161 | m_point = point; 162 | } 163 | } 164 | } 165 | 166 | // Assign a color using the closest point position 167 | color += dot(m_point,vec2(.3,.6)); 168 | color *= 1.0 - blending*m_dist; 169 | return vec4(color, 1.0); 170 | } 171 | ` 172 | }, 173 | osc: { 174 | type: 'src', 175 | inputs: [ 176 | { 177 | name: 'frequency', 178 | type: 'float', 179 | default: 60.0 180 | }, 181 | { 182 | name: 'sync', 183 | type: 'float', 184 | default: 0.1 185 | }, 186 | { 187 | name: 'offset', 188 | type: 'float', 189 | default: 0.0 190 | }, 191 | { 192 | name: 'time', 193 | type: 'float', 194 | default: 'time' 195 | } 196 | ], 197 | glsl: `vec4 osc(vec2 _st, float freq, float sync, float offset, float time){ 198 | vec2 st = _st; 199 | float r = sin((st.x-offset/freq+time*sync)*freq)*0.5 + 0.5; 200 | float g = sin((st.x+time*sync)*freq)*0.5 + 0.5; 201 | float b = sin((st.x+offset/freq+time*sync)*freq)*0.5 + 0.5; 202 | return vec4(r, g, b, 1.0); 203 | } 204 | ` 205 | }, 206 | shape: { 207 | type: 'src', 208 | inputs: [ 209 | { 210 | name: 'sides', 211 | type: 'float', 212 | default: 3.0 213 | }, 214 | { 215 | name: 'radius', 216 | type: 'float', 217 | default: 0.3 218 | }, 219 | { 220 | name: 'smoothing', 221 | type: 'float', 222 | default: 0.01 223 | } 224 | ], 225 | glsl: `vec4 shape(vec2 _st, float sides, float radius, float smoothing){ 226 | vec2 st = _st * 2. - 1.; 227 | // Angle and radius from the current pixel 228 | float a = atan(st.x,st.y)+3.1416; 229 | float r = (2.*3.1416)/sides; 230 | float d = cos(floor(.5+a/r)*r-a)*length(st); 231 | return vec4(vec3(1.0-smoothstep(radius,radius + smoothing,d)), 1.0); 232 | } 233 | ` 234 | }, 235 | gradient: { 236 | type: 'src', 237 | inputs: [ 238 | { 239 | name: 'speed', 240 | type: 'float', 241 | default: 0.0 242 | }, 243 | { 244 | name: 'time', 245 | type: 'float', 246 | default: 'time' 247 | } 248 | ], 249 | glsl: `vec4 gradient(vec2 _st, float speed, float time) { 250 | return vec4(_st, sin(time*speed), 1.0); 251 | } 252 | ` 253 | }, 254 | src: { 255 | type: 'src', 256 | inputs: [ 257 | { 258 | name: 'tex', 259 | type: 'texture' 260 | } 261 | ], 262 | glsl: `vec4 src(vec2 _st, texture2d _tex){ 263 | return _tex.sample(_sampler,fract(_st)); 264 | } 265 | ` 266 | }, 267 | solid: { 268 | type: 'src', 269 | inputs: [ 270 | { 271 | name: 'r', 272 | type: 'float', 273 | default: 0.0 274 | }, 275 | { 276 | name: 'g', 277 | type: 'float', 278 | default: 0.0 279 | }, 280 | { 281 | name: 'b', 282 | type: 'float', 283 | default: 0.0 284 | }, 285 | { 286 | name: 'a', 287 | type: 'float', 288 | default: 1.0 289 | } 290 | ], 291 | notes: '', 292 | glsl: `vec4 solid(vec2 uv, float _r, float _g, float _b, float _a){ 293 | return vec4(_r, _g, _b, _a); 294 | } 295 | ` 296 | }, 297 | rotate: { 298 | type: 'coord', 299 | inputs: [ 300 | { 301 | name: 'angle', 302 | type: 'float', 303 | default: 10.0 304 | }, { 305 | name: 'speed', 306 | type: 'float', 307 | default: 0.0 308 | }, 309 | { 310 | name: 'time', 311 | type: 'float', 312 | default: 'time' 313 | } 314 | ], 315 | glsl: `vec2 rotate(vec2 st, float _angle, float speed, float time){ 316 | vec2 xy = st - vec2(0.5); 317 | float angle = _angle + speed *time; 318 | xy = mat2(cos(angle),-sin(angle), sin(angle),cos(angle))*xy; 319 | xy += 0.5; 320 | return xy; 321 | } 322 | ` 323 | }, 324 | scale: { 325 | type: 'coord', 326 | inputs: [ 327 | { 328 | name: 'amount', 329 | type: 'float', 330 | default: 1.5 331 | }, 332 | { 333 | name: 'xMult', 334 | type: 'float', 335 | default: 1.0 336 | }, 337 | { 338 | name: 'yMult', 339 | type: 'float', 340 | default: 1.0 341 | }, 342 | { 343 | name: 'offsetX', 344 | type: 'float', 345 | default: 0.5 346 | }, 347 | { 348 | name: 'offsetY', 349 | type: 'float', 350 | default: 0.5 351 | } 352 | ], 353 | glsl: `vec2 scale(vec2 st, float amount, float xMult, float yMult, float offsetX, float offsetY){ 354 | vec2 xy = st - vec2(offsetX, offsetY); 355 | xy*=(1.0/vec2(amount*xMult, amount*yMult)); 356 | xy+=vec2(offsetX, offsetY); 357 | return xy; 358 | } 359 | ` 360 | }, 361 | pixelate: { 362 | type: 'coord', 363 | inputs: [ 364 | { 365 | name: 'pixelX', 366 | type: 'float', 367 | default: 20 368 | }, { 369 | name: 'pixelY', 370 | type: 'float', 371 | default: 20 372 | } 373 | ], 374 | glsl: `vec2 pixelate(vec2 st, float pixelX, float pixelY){ 375 | vec2 xy = vec2(pixelX, pixelY); 376 | return (floor(st * xy) + 0.5)/xy; 377 | } 378 | ` 379 | }, 380 | posterize: { 381 | type: 'color', 382 | inputs: [ 383 | { 384 | name: 'bins', 385 | type: 'float', 386 | default: 3.0 387 | }, 388 | { 389 | name: 'gamma', 390 | type: 'float', 391 | default: 0.6 392 | } 393 | ], 394 | glsl: `vec4 posterize(vec4 c, float bins, float gamma){ 395 | vec4 c2 = pow(c, vec4(gamma)); 396 | c2 *= vec4(bins); 397 | c2 = floor(c2); 398 | c2/= vec4(bins); 399 | c2 = pow(c2, vec4(1.0/gamma)); 400 | return vec4(c2.xyz, c.a); 401 | } 402 | ` 403 | }, 404 | shift: { 405 | type: 'color', 406 | inputs: [ 407 | { 408 | name: 'r', 409 | type: 'float', 410 | default: 0.5 411 | }, 412 | { 413 | name: 'g', 414 | type: 'float', 415 | default: 0.0 416 | }, 417 | { 418 | name: 'b', 419 | type: 'float', 420 | default: 0.0 421 | }, 422 | { 423 | name: 'a', 424 | type: 'float', 425 | default: 0.0 426 | } 427 | ], 428 | glsl: `vec4 shift(vec4 c, float r, float g, float b, float a){ 429 | vec4 c2 = vec4(c); 430 | c2.r = fract(c2.r + r); 431 | c2.g = fract(c2.g + g); 432 | c2.b = fract(c2.b + b); 433 | c2.a = fract(c2.a + a); 434 | return vec4(c2.rgba); 435 | } 436 | ` 437 | }, 438 | repeat: { 439 | type: 'coord', 440 | inputs: [ 441 | { 442 | name: 'repeatX', 443 | type: 'float', 444 | default: 3.0 445 | }, 446 | { 447 | name: 'repeatY', 448 | type: 'float', 449 | default: 3.0 450 | }, 451 | { 452 | name: 'offsetX', 453 | type: 'float', 454 | default: 0.0 455 | }, 456 | { 457 | name: 'offsetY', 458 | type: 'float', 459 | default: 0.0 460 | } 461 | ], 462 | glsl: `vec2 repeat(vec2 _st, float repeatX, float repeatY, float offsetX, float offsetY){ 463 | vec2 st = _st * vec2(repeatX, repeatY); 464 | st.x += step(1., mod(st.y,2.0)) * offsetX; 465 | st.y += step(1., mod(st.x,2.0)) * offsetY; 466 | return fract(st); 467 | } 468 | ` 469 | }, 470 | modulateRepeat: { 471 | type: 'combineCoord', 472 | inputs: [ 473 | { 474 | name: 'color', 475 | type: 'vec4' 476 | }, 477 | { 478 | name: 'repeatX', 479 | type: 'float', 480 | default: 3.0 481 | }, 482 | { 483 | name: 'repeatY', 484 | type: 'float', 485 | default: 3.0 486 | }, 487 | { 488 | name: 'offsetX', 489 | type: 'float', 490 | default: 0.5 491 | }, 492 | { 493 | name: 'offsetY', 494 | type: 'float', 495 | default: 0.5 496 | } 497 | ], 498 | glsl: `vec2 modulateRepeat(vec2 _st, vec4 c1, float repeatX, float repeatY, float offsetX, float offsetY){ 499 | vec2 st = _st * vec2(repeatX, repeatY); 500 | st.x += step(1., mod(st.y,2.0)) + c1.r * offsetX; 501 | st.y += step(1., mod(st.x,2.0)) + c1.g * offsetY; 502 | return fract(st); 503 | } 504 | ` 505 | }, 506 | repeatX: { 507 | type: 'coord', 508 | inputs: [ 509 | { 510 | name: 'reps', 511 | type: 'float', 512 | default: 3.0 513 | }, { 514 | name: 'offset', 515 | type: 'float', 516 | default: 0.0 517 | } 518 | ], 519 | glsl: `vec2 repeatX(vec2 _st, float reps, float offset){ 520 | vec2 st = _st * vec2(reps, 1.0); 521 | // float f = mod(_st.y,2.0); 522 | st.y += step(1., mod(st.x,2.0))* offset; 523 | return fract(st); 524 | } 525 | ` 526 | }, 527 | modulateRepeatX: { 528 | type: 'combineCoord', 529 | inputs: [ 530 | { 531 | name: 'color', 532 | type: 'vec4' 533 | }, 534 | { 535 | name: 'reps', 536 | type: 'float', 537 | default: 3.0 538 | }, 539 | { 540 | name: 'offset', 541 | type: 'float', 542 | default: 0.5 543 | } 544 | ], 545 | glsl: `vec2 modulateRepeatX(vec2 _st, vec4 c1, float reps, float offset){ 546 | vec2 st = _st * vec2(reps, 1.0); 547 | // float f = mod(_st.y,2.0); 548 | st.y += step(1., mod(st.x,2.0)) + c1.r * offset; 549 | return fract(st); 550 | } 551 | ` 552 | }, 553 | repeatY: { 554 | type: 'coord', 555 | inputs: [ 556 | { 557 | name: 'reps', 558 | type: 'float', 559 | default: 3.0 560 | }, { 561 | name: 'offset', 562 | type: 'float', 563 | default: 0.0 564 | } 565 | ], 566 | glsl: `vec2 repeatY(vec2 _st, float reps, float offset){ 567 | vec2 st = _st * vec2(1.0, reps); 568 | // float f = mod(_st.y,2.0); 569 | st.x += step(1., mod(st.y,2.0))* offset; 570 | return fract(st); 571 | } 572 | ` 573 | }, 574 | modulateRepeatY: { 575 | type: 'combineCoord', 576 | inputs: [ 577 | { 578 | name: 'color', 579 | type: 'vec4' 580 | }, 581 | { 582 | name: 'reps', 583 | type: 'float', 584 | default: 3.0 585 | }, 586 | { 587 | name: 'offset', 588 | type: 'float', 589 | default: 0.5 590 | } 591 | ], 592 | glsl: `vec2 modulateRepeatY(vec2 _st, vec4 c1, float reps, float offset){ 593 | vec2 st = _st * vec2(reps, 1.0); 594 | // float f = mod(_st.y,2.0); 595 | st.x += step(1., mod(st.y,2.0)) + c1.r * offset; 596 | return fract(st); 597 | } 598 | ` 599 | }, 600 | clamp: { 601 | type: 'coord', 602 | inputs: [ 603 | { 604 | name: 'min', 605 | type: 'float', 606 | default: 0.0 607 | }, 608 | { 609 | name: 'max', 610 | type: 'float', 611 | default: 1.0 612 | } 613 | ], 614 | glsl: '', 615 | example: ` 616 | osc(5,0,1) 617 | .scale(0.5) 618 | .clamp(0.0,1.0) 619 | .out(o0)`, 620 | }, 621 | kaleid: { 622 | type: 'coord', 623 | inputs: [ 624 | { 625 | name: 'nSides', 626 | type: 'float', 627 | default: 4.0 628 | } 629 | ], 630 | glsl: `vec2 kaleid(vec2 st, float nSides){ 631 | st -= 0.5; 632 | float r = length(st); 633 | float a = atan(st.y, st.x); 634 | float pi = 2.*3.1416; 635 | a = mod(a,pi/nSides); 636 | a = abs(a-pi/nSides/2.); 637 | return r*vec2(cos(a), sin(a)); 638 | } 639 | ` 640 | }, 641 | modulateKaleid: { 642 | type: 'combineCoord', 643 | inputs: [ 644 | { 645 | name: 'color', 646 | type: 'vec4' 647 | }, 648 | { 649 | name: 'nSides', 650 | type: 'float', 651 | default: 4.0 652 | } 653 | ], 654 | glsl: `vec2 modulateKaleid(vec2 st, vec4 c1, float nSides){ 655 | st -= 0.5; 656 | float r = length(st); 657 | float a = atan(st.y, st.x); 658 | float pi = 2.*3.1416; 659 | a = mod(a,pi/nSides); 660 | a = abs(a-pi/nSides/2.); 661 | return (c1.r+r)*vec2(cos(a), sin(a)); 662 | } 663 | ` 664 | }, 665 | scrollX: { 666 | type: 'coord', 667 | inputs: [ 668 | { 669 | name: 'scrollX', 670 | type: 'float', 671 | default: 0.5 672 | }, 673 | { 674 | name: 'speed', 675 | type: 'float', 676 | default: 0.0 677 | }, 678 | { 679 | name: 'time', 680 | type: 'float', 681 | default: 'time' 682 | } 683 | ], 684 | glsl: `vec2 scrollX(vec2 st, float amount, float speed, float time){ 685 | st.x += amount + time*speed; 686 | return fract(st); 687 | } 688 | ` 689 | }, 690 | modulateScrollX: { 691 | type: 'combineCoord', 692 | inputs: [ 693 | { 694 | name: 'color', 695 | type: 'vec4' 696 | }, 697 | { 698 | name: 'scrollX', 699 | type: 'float', 700 | default: 0.5 701 | }, 702 | { 703 | name: 'speed', 704 | type: 'float', 705 | default: 0.0 706 | }, 707 | { 708 | name: 'time', 709 | type: 'float', 710 | default: 'time' 711 | } 712 | ], 713 | glsl: `vec2 modulateScrollX(vec2 st, vec4 c1, float amount, float speed, float time){ 714 | st.x += c1.r*amount + time*speed; 715 | return fract(st); 716 | } 717 | ` 718 | }, 719 | scrollY: { 720 | type: 'coord', 721 | inputs: [ 722 | { 723 | name: 'scrollY', 724 | type: 'float', 725 | default: 0.5 726 | }, 727 | { 728 | name: 'speed', 729 | type: 'float', 730 | default: 0.0 731 | }, 732 | { 733 | name: 'time', 734 | type: 'float', 735 | default: 'time' 736 | } 737 | ], 738 | glsl: `vec2 scrollY(vec2 st, float amount, float speed, float time){ 739 | st.y += amount + time*speed; 740 | return fract(st); 741 | } 742 | ` 743 | }, 744 | modulateScrollY: { 745 | type: 'combineCoord', 746 | inputs: [ 747 | { 748 | name: 'color', 749 | type: 'vec4' 750 | }, 751 | { 752 | name: 'scrollY', 753 | type: 'float', 754 | default: 0.5 755 | }, 756 | { 757 | name: 'speed', 758 | type: 'float', 759 | default: 0.0 760 | }, 761 | { 762 | name: 'time', 763 | type: 'float', 764 | default: 'time' 765 | } 766 | ], 767 | glsl: `vec2 modulateScrollY(vec2 st, vec4 c1, float amount, float speed, float time){ 768 | st.y += c1.r*amount + time*speed; 769 | return fract(st); 770 | } 771 | ` 772 | }, 773 | add: { 774 | type: 'combine', 775 | inputs: [ 776 | { 777 | name: 'color', 778 | type: 'vec4' 779 | }, 780 | { 781 | name: 'amount', 782 | type: 'float', 783 | default: 0.5 784 | } 785 | ], 786 | glsl: `vec4 add(vec4 c0, vec4 c1, float amount){ 787 | return (c0+c1)*amount + c0*(1.0-amount); 788 | } 789 | ` 790 | }, 791 | layer: { 792 | type: 'combine', 793 | inputs: [ 794 | { 795 | name: 'color', 796 | type: 'vec4' 797 | } 798 | ], 799 | glsl: `vec4 layer(vec4 c0, vec4 c1){ 800 | return vec4(mix(c0.rgb, c1.rgb, c1.a), c0.a+c1.a); 801 | } 802 | ` 803 | }, 804 | blend: { 805 | type: 'combine', 806 | inputs: [ 807 | { 808 | name: 'color', 809 | type: 'vec4' 810 | }, 811 | { 812 | name: 'amount', 813 | type: 'float', 814 | default: 0.5 815 | } 816 | ], 817 | glsl: `vec4 blend(vec4 c0, vec4 c1, float amount){ 818 | return c0*(1.0-amount)+c1*amount; 819 | } 820 | ` 821 | }, 822 | mult: { 823 | type: 'combine', 824 | inputs: [ 825 | { 826 | name: 'color', 827 | type: 'vec4' 828 | }, 829 | { 830 | name: 'amount', 831 | type: 'float', 832 | default: 1.0 833 | } 834 | ], 835 | glsl: `vec4 mult(vec4 c0, vec4 c1, float amount){ 836 | return c0*(1.0-amount)+(c0*c1)*amount; 837 | } 838 | ` 839 | }, 840 | 841 | diff: { 842 | type: 'combine', 843 | inputs: [ 844 | { 845 | name: 'color', 846 | type: 'vec4' 847 | } 848 | ], 849 | glsl: `vec4 diff(vec4 c0, vec4 c1){ 850 | return vec4(abs(c0.rgb-c1.rgb), max(c0.a, c1.a)); 851 | } 852 | ` 853 | }, 854 | 855 | modulate: { 856 | type: 'combineCoord', 857 | inputs: [ 858 | { 859 | name: 'color', 860 | type: 'vec4' 861 | }, 862 | { 863 | name: 'amount', 864 | type: 'float', 865 | default: 0.1 866 | } 867 | ], 868 | glsl: `vec2 modulate(vec2 st, vec4 c1, float amount){ 869 | // return fract(st+(c1.xy-0.5)*amount); 870 | return st + c1.xy*amount; 871 | } 872 | ` 873 | }, 874 | modulateScale: { 875 | type: 'combineCoord', 876 | inputs: [ 877 | { 878 | name: 'color', 879 | type: 'vec4' 880 | }, 881 | { 882 | name: 'multiple', 883 | type: 'float', 884 | default: 1.0 885 | }, 886 | { 887 | name: 'offset', 888 | type: 'float', 889 | default: 1.0 890 | } 891 | ], 892 | glsl: `vec2 modulateScale(vec2 st, vec4 c1, float multiple, float offset){ 893 | vec2 xy = st - vec2(0.5); 894 | xy*=(1.0/vec2(offset + multiple*c1.r, offset + multiple*c1.g)); 895 | xy+=vec2(0.5); 896 | return xy; 897 | } 898 | ` 899 | }, 900 | modulatePixelate: { 901 | type: 'combineCoord', 902 | inputs: [ 903 | { 904 | name: 'color', 905 | type: 'vec4' 906 | }, 907 | { 908 | name: 'multiple', 909 | type: 'float', 910 | default: 10.0 911 | }, 912 | { 913 | name: 'offset', 914 | type: 'float', 915 | default: 3.0 916 | } 917 | ], 918 | glsl: `vec2 modulatePixelate(vec2 st, vec4 c1, float multiple, float offset){ 919 | vec2 xy = vec2(offset + c1.x*multiple, offset + c1.y*multiple); 920 | return (floor(st * xy) + 0.5)/xy; 921 | } 922 | ` 923 | }, 924 | modulateRotate: { 925 | type: 'combineCoord', 926 | inputs: [ 927 | { 928 | name: 'color', 929 | type: 'vec4' 930 | }, 931 | { 932 | name: 'multiple', 933 | type: 'float', 934 | default: 1.0 935 | }, 936 | { 937 | name: 'offset', 938 | type: 'float', 939 | default: 0.0 940 | } 941 | ], 942 | glsl: `vec2 modulateRotate(vec2 st, vec4 c1, float multiple, float offset){ 943 | vec2 xy = st - vec2(0.5); 944 | float angle = offset + c1.x * multiple; 945 | xy = mat2(cos(angle),-sin(angle), sin(angle),cos(angle))*xy; 946 | xy += 0.5; 947 | return xy; 948 | } 949 | ` 950 | }, 951 | modulateHue: { 952 | type: 'combineCoord', 953 | notes: 'changes coordinates based on hue of second input. Based on: https://www.shadertoy.com/view/XtcSWM', 954 | inputs: [ 955 | { 956 | name: 'color', 957 | type: 'vec4' 958 | }, 959 | { 960 | name: 'amount', 961 | type: 'float', 962 | default: 1.0 963 | }, 964 | { 965 | name: 'resolution', 966 | type: 'vec2', 967 | default: 'resolution' 968 | } 969 | ], 970 | glsl: `vec2 modulateHue(vec2 st, vec4 c1, float amount, vec2 resolution){ 971 | return st + (vec2(c1.g - c1.r, c1.b - c1.g) * amount * 1.0/resolution.xy); 972 | } 973 | ` 974 | }, 975 | invert: { 976 | type: 'color', 977 | inputs: [ 978 | { 979 | name: 'amount', 980 | type: 'float', 981 | default: 1.0 982 | } 983 | ], 984 | glsl: `vec4 invert(vec4 c0, float amount){ 985 | return vec4((1.0-c0.rgb)*amount + c0.rgb*(1.0-amount), c0.a); 986 | } 987 | ` 988 | }, 989 | contrast: { 990 | type: 'color', 991 | inputs: [ 992 | { 993 | name: 'amount', 994 | type: 'float', 995 | default: 1.6 996 | } 997 | ], 998 | glsl: `vec4 contrast(vec4 c0, float amount) { 999 | vec4 c = (c0-vec4(0.5))*vec4(amount) + vec4(0.5); 1000 | return vec4(c.rgb, c0.a); 1001 | } 1002 | ` 1003 | }, 1004 | brightness: { 1005 | type: 'color', 1006 | inputs: [ 1007 | { 1008 | name: 'amount', 1009 | type: 'float', 1010 | default: 0.4 1011 | } 1012 | ], 1013 | glsl: `vec4 brightness(vec4 c0, float amount){ 1014 | return vec4(c0.rgb + vec3(amount), c0.a); 1015 | } 1016 | ` 1017 | }, 1018 | luminance: { 1019 | type: 'util', 1020 | glsl: `float luminance(vec3 rgb){ 1021 | const vec3 W = vec3(0.2125, 0.7154, 0.0721); 1022 | return dot(rgb, W); 1023 | }` 1024 | }, 1025 | mask: { 1026 | type: 'combine', 1027 | inputs: [ 1028 | { 1029 | name: 'color', 1030 | type: 'vec4' 1031 | } 1032 | ], 1033 | glsl: `vec4 mask(vec4 c0, vec4 c1){ 1034 | float a = luminance(c1.rgb); 1035 | return vec4(c0.rgb*a, a); 1036 | }` 1037 | }, 1038 | luma: { 1039 | type: 'color', 1040 | inputs: [ 1041 | { 1042 | name: 'threshold', 1043 | type: 'float', 1044 | default: 0.5 1045 | }, 1046 | { 1047 | name: 'tolerance', 1048 | type: 'float', 1049 | default: 0.1 1050 | } 1051 | ], 1052 | glsl: `vec4 luma(vec4 c0, float threshold, float tolerance){ 1053 | float a = smoothstep(threshold-tolerance, threshold+tolerance, luminance(c0.rgb)); 1054 | return vec4(c0.rgb*a, a); 1055 | } 1056 | ` 1057 | }, 1058 | thresh: { 1059 | type: 'color', 1060 | inputs: [ 1061 | { 1062 | name: 'threshold', 1063 | type: 'float', 1064 | default: 0.5 1065 | }, { 1066 | name: 'tolerance', 1067 | type: 'float', 1068 | default: 0.04 1069 | } 1070 | ], 1071 | glsl: `vec4 thresh(vec4 c0, float threshold, float tolerance){ 1072 | return vec4(vec3(smoothstep(threshold-tolerance, threshold+tolerance, luminance(c0.rgb))), c0.a); 1073 | } 1074 | ` 1075 | }, 1076 | color: { 1077 | type: 'color', 1078 | inputs: [ 1079 | { 1080 | name: 'r', 1081 | type: 'float', 1082 | default: 1.0 1083 | }, 1084 | { 1085 | name: 'g', 1086 | type: 'float', 1087 | default: 1.0 1088 | }, 1089 | { 1090 | name: 'b', 1091 | type: 'float', 1092 | default: 1.0 1093 | }, 1094 | { 1095 | name: 'a', 1096 | type: 'float', 1097 | default: 1.0 1098 | } 1099 | ], 1100 | notes: 'https://www.youtube.com/watch?v=FpOEtm9aX0M', 1101 | glsl: `vec4 color(vec4 c0, float _r, float _g, float _b, float _a){ 1102 | vec4 c = vec4(_r, _g, _b, _a); 1103 | vec4 pos = step(0.0, c); // detect whether negative 1104 | 1105 | // if > 0, return r * c0 1106 | // if < 0 return (1.0-r) * c0 1107 | return vec4(mix((1.0-c0)*abs(c), c*c0, pos)); 1108 | } 1109 | ` 1110 | }, 1111 | _rgbToHsv: { 1112 | type: 'util', 1113 | glsl: `vec3 _rgbToHsv(vec3 c){ 1114 | vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); 1115 | vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); 1116 | vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); 1117 | float d = q.x - min(q.w, q.y); 1118 | return vec3(abs(q.z+((d==0.0)?1.0:((q.w-q.y)/(6.0*d)))), (q.x==0.0)?3.402823466e+38:(d/q.x), q.x); 1119 | } 1120 | ` 1121 | }, 1122 | _hsvToRgb: { 1123 | type: 'util', 1124 | glsl: `vec3 _hsvToRgb(vec3 c){ 1125 | vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); 1126 | vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); 1127 | return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); 1128 | } 1129 | ` 1130 | }, 1131 | saturate: { 1132 | type: 'color', 1133 | inputs: [ 1134 | { 1135 | name: 'amount', 1136 | type: 'float', 1137 | default: 2.0 1138 | } 1139 | ], 1140 | glsl: `vec4 saturate(vec4 c0, float amount){ 1141 | const vec3 W = vec3(0.2125, 0.7154, 0.0721); 1142 | vec3 intensity = vec3(dot(c0.rgb, W)); 1143 | return vec4(mix(intensity, c0.rgb, amount), c0.a); 1144 | } 1145 | ` 1146 | }, 1147 | hue: { 1148 | type: 'color', 1149 | inputs: [ 1150 | { 1151 | name: 'hue', 1152 | type: 'float', 1153 | default: 0.4 1154 | } 1155 | ], 1156 | glsl: `vec4 hue(vec4 c0, float hue){ 1157 | vec3 c = _rgbToHsv(c0.rgb); 1158 | c.r += hue; 1159 | // c.r = fract(c.r); 1160 | return vec4(_hsvToRgb(c), c0.a); 1161 | } 1162 | ` 1163 | }, 1164 | colorama: { 1165 | type: 'color', 1166 | inputs: [ 1167 | { 1168 | name: 'amount', 1169 | type: 'float', 1170 | default: 0.005 1171 | } 1172 | ], 1173 | glsl: `vec4 colorama(vec4 c0, float amount){ 1174 | vec3 c = _rgbToHsv(c0.rgb); 1175 | c += vec3(amount); 1176 | c = _hsvToRgb(c); 1177 | c = fract(c); 1178 | return vec4(c, c0.a); 1179 | } 1180 | ` 1181 | } 1182 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | --------------------------------------------------------------------------------