summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fractiform.js22
-rw-r--r--index.html7
2 files changed, 26 insertions, 3 deletions
diff --git a/fractiform.js b/fractiform.js
index dcc85b9..cfcfaab 100644
--- a/fractiform.js
+++ b/fractiform.js
@@ -2,9 +2,8 @@
/*
TODO:
-- draw lines btwn vertex positions and uvs
-- synthlike interface? (change name to fraxynth?)
-- grid
+- detect circular dependencies
+- detect duplicate widget names
*/
let gl;
@@ -231,6 +230,7 @@ class GLSLGenerationState {
}
compute_input(input) {
+ input = input.trim();
if (this.has_error) return null;
if (!isNaN(input)) return { code: float_glsl(parseFloat(input)), type: 'float' };
@@ -314,6 +314,8 @@ class GLSLGenerationState {
switch (input) {
case '.pos':
return {code: 'uv', type: 'vec2'};
+ case '.time':
+ return {code: 'u_time', type: 'float'};
default:
this.error(`no such builtin: ${input}`);
return null;
@@ -368,6 +370,18 @@ class GLSLGenerationState {
ret = {type: type, code: v};
}
break;
+ case 'prev': {
+ let pos = this.compute_input(widget.inputs['pos']);
+ if (this.has_error) return null;
+ if (pos.type !== 'vec2') {
+ this.error('bad type for sample position: ' + pos.type);
+ return null;
+ }
+
+ let v = this.next_variable();
+ this.add_code(`vec3 ${v} = texture2D(u_texture, ${pos.code}).xyz;\n`);
+ ret = {type: 'vec3', code: v};
+ } break;
case 'output':
ret = this.compute_input(widget.inputs['value']);
break;
@@ -622,6 +636,8 @@ function compile_program(name, shaders) {
show_error('unrecognized shader type: ' + type);
}
let shader = compile_shader(name + ' ' + type, gl_type, source);
+ if (shader === null)
+ return null;
gl.attachShader(program, shader);
}
diff --git a/index.html b/index.html
index ef7c410..41251e0 100644
--- a/index.html
+++ b/index.html
@@ -157,6 +157,13 @@
<div class="out">out</div>
</div>
</div>
+ <div class="widget" data-func="prev">
+ <div class="widget-title">Last frame <input placeholder="name" class="name" type="text"></div>
+ <div class="in"><input type="text" id="bpos"> <label for="bpos">pos</label></div>
+ <div class="outs">
+ <div class="out">out</div>
+ </div>
+ </div>
<div class="widget" data-func="output">
<div class="widget-title">Output Color</div>
<div class="in"><input type="text" id="out"> <label for="out">value</label></div>