xxxxxxxxxx
43
let shaderGraphics;
let sh;
let dataShader;
let buf01, buf02;
function preload(){
sh = loadShader('shader.vert', 'shader.frag');
dataShader = loadShader('shader.vert','data.frag');
}
function setup(){
pixelDensity(1);
createCanvas(windowWidth, windowHeight, WEBGL);
shaderGraphics = createGraphics(windowWidth, windowHeight, WEBGL);
shaderGraphics.shader(sh);
buf01 = createGraphics(windowWidth, windowHeight, WEBGL);
buf02 = createGraphics(windowWidth, windowHeight, WEBGL);
buf01.shader(dataShader);
buf02.shader(dataShader);
buf01.clear();
buf02.background(1);
}
function draw(){
buf01.shader(dataShader);
dataShader.setUniform("backbuffer",buf02);
dataShader.setUniform("resolution",[windowWidth,windowHeight]);
buf01.clear();
buf01.quad(-1,-1,1,-1,1,1,-1,1);
[buf01, buf02] = [buf02, buf01];
resetShader();
shaderGraphics.shader(sh);
sh.setUniform("resolution", [windowWidth,windowHeight]);
sh.setUniform("data", buf01);
shaderGraphics.quad(-1,-1,1,-1,1,1,-1,1);
image(shaderGraphics,width*-0.5, height*-0.5);
}