Hello, I’m trying to make my shader fade in every 8 - 10 seconds and then fade out and have my video playing in the back. However, I just seem to make it fade in and can’t figure out how to make it fade out. I think there may be an issue in changing the variable transitionAlpha.
import processing.video.*;
PGraphics pg;
PShader glitch;
PImage img;
Movie myMovie;
// Load all of these separate files in setup()
//Movie[] myMovie = new Movie[one.length]; // e.g.
int arr = 0;
int a = 0;
float md = 0;
float mt = 0;
int idx = 0;
//fadein + fadeout transition
int time = 0;
int lastTime = 0;
int fadeout = 0;
int fadein = 255;
boolean vidfadesin = true;
boolean transition = true;
float transitionAlpha = 0.0;
void setup() {
size(1000, 562, P3D); // 1920/2, 1080/2
background(0);
// all .mp4s
myMovie = new Movie(this, "v1-19.mp4");
myMovie.loop();
//pgraphics
pg = createGraphics(width, height, P3D);
noStroke();
img = loadImage("texture.jpeg");
//shaders
glitch = loadShader("shrtoy.frag");
glitch.set("u_resolution", float(width), float(height));
glitch.set("u_channel1", img);
rectMode(CORNER);
}
void movieEvent(Movie m) {
m.read();
}
void draw()
{
glitch.set("u_time", millis() / 1000.0);
glitch.set("u_channel0", myMovie);
background(0);
int timeDelay = int(random(8000, 10000));
pg.beginDraw();
if (transition == true) {
pg.tint(255, fadein - transitionAlpha);
pg.filter(glitch);
pg.image(myMovie, 0, 0, width, height);
} else {
pg.tint(255, fadeout + transitionAlpha);
//pg.filter(glitch);
pg.image(myMovie, 0, 0, width, height);
}
transitionAlpha += 6;
if (transitionAlpha > 255) {
if (millis() - time >= timeDelay) {
time = millis();
transitionAlpha -= 1;
fadein = 0;
fadeout = 255;
}
}
pg.endDraw();
image(pg, 0, 0);
}