Duotone
Applies a two-tone color effect.
Parameters
texture
Texture: The input texture to be filtered. Default: undefined
tone1
Vec2: The RGB values of the first tone. Default: (0.0, 0.0, 0.0)
tone2
Vec2: The RGB values of the second tone. Default: (0.0, 0.0, 0.0)
Example
let layer,
bird,
duoTone;
function preload() {
duoTone = createShader(fip.defaultVert, fip.duoTone); // Load the shader
bird = loadImage("bird.jpg");
}
function setup() {
createCanvas(600, 600, WEBGL); // Use WEBGL mode to use the shader
layer = createFramebuffer(); // Create a framebuffer to draw the image onto
}
function draw() {
background(0);
// Draw an image to a framebuffer
layer.begin();
clear();
scale(1, -1); // Flip the Y-axis to match the canvas (different coordinate system in framebuffer)
image(bird, -width / 2, -height / 2, width, height);
layer.end();
// Apply the shader
shader(duoTone);
// Set the shader uniforms
duoTone.setUniform("texture", layer.color); // Set the texture to apply the shader to
duoTone.setUniform('tone1', [0.8627, 0.6275, 0.0]);
duoTone.setUniform('tone2', [0.4157, 0.0118, 0.5647]);
rect(0, 0, width, height); // Draw a rectangle to apply the shader to
resetShader();
}