xxxxxxxxxx
var theShader;
var shaderTexture;
function preload(){
// load the shader
theShader = loadShader('texture.vert','texture.frag');
}
function setup() {
// shaders require WEBGL mode to work
createCanvas(windowWidth, windowHeight, WEBGL);
noStroke();
noSmooth();
pixelDensity(1);
// initialize the createGraphics layers
// FBO (frame buffer object):
shaderTexture = createGraphics(10, 10, WEBGL);
shaderTexture.noStroke();
}
function draw() {
// 1 - set the parameters to the shader:
theShader.setUniform("resolution", [shaderTexture.width, shaderTexture.height]);
theShader.setUniform("time", millis() / 1000.0);
theShader.setUniform("mouse", [mouseX/width*20, mouseY/height*20]);
// 2 - run the shader in the FBO
shaderTexture.noSmooth();
shaderTexture.shader(theShader); // executes the code
shaderTexture.rect(0,0,width,height); // draws an output that is going to have it
background(255);
// 3 - use the output of the shader as a texture
texture(shaderTexture);
// 4 - draw whatever
plane(width,height);
}