void ofApp::setup(){
//ofSetLogLevel(OF_LOG_VERBOSE);
ofSetWindowShape(900,960);
ofSetWindowTitle("glitch");
ofSetFrameRate(8);
vid.load("ML.mp4");
//img.load("RUNE.png");
vid.setLoopState(OF_LOOP_NORMAL);
shaderB.load("glitch2");
shader.load("glitch");
vid.play();
ofFboSettings s;
s.width =vid.getWidth();
s.height =vid.getHeight();
s.internalformat =GL_RGBA;
s.useDepth = true;
fbo.allocate(s);
ofFboSettings v;
v.width = 900;
v.height = 960;
v.internalformat =GL_RGBA;
v.useDepth = true;
fbo0.allocate(v);
gui.setup();
gui.add(valueA.set("Value A",0.0005,0.0,1.0));
gui.add(valueB.set("Value B",0.0001,0,1));
for(int i = 0; i < fbo.getHeight(); i++)
{
y_noise.push_back(glm::vec3(0.f,0.f,0.f));
}
showGui = false;
scene = false;
mRenderer.setup(ofGetWidth(), ofGetHeight());
}
//--------------------------------------------------------------
void ofApp::update(){
vid.update();
fbo.begin();
ofClear(0);
fbo.end();
fbo0.begin();
ofClear(0);
fbo0.end();
glm::vec3 noise_value;
for(int y = 0; y < y_noise.size(); y++)
{
for(int i = 0; i < 3; i++)
{
noise_value[i] = ofMap(ofNoise(i,y *valueA +ofGetElapsedTimef()*valueB) ,0,1,-1,1);
}
y_noise[y] = noise_value;
}
}
//--------------------------------------------------------------
void ofApp::draw(){
fbo.begin();
vid.draw(0,0,900,960);
fbo.end();
fbo0.begin();
//ofBackground(ofColor::black);
//svg.draw();
img.draw(0,0);
//ofDrawRectangle(0,0,40,40);
fbo0.end();
mRenderer.begin();
if (scene)
{
shaderB.begin();
shaderB.setUniform1f("u_time",ofGetElapsedTimef());
shaderB.setUniformTexture("u_tex0",fbo0.getTexture(),1);
shaderB.setUniform2f("u_resolution",900,960);
fbo0.draw(0,0);
shaderB.end();
}else
{
shader.begin();
shader.setUniform1f("u_time",ofGetElapsedTimef());
shader.setUniform2f("u_resolution",900,960);
shader.setUniformTexture("u_tex0",fbo.getTexture(),1);
shader.setUniform1f("u_date",ofGetDay());
shader.setUniform3fv("y_noise", &y_noise[0].x,ofGetHeight());
fbo.draw(0,0);
shader.end();
}
mRenderer.end();
the shader
#version 150
out vec4 outputColor;
uniform float u_time;
// uniform float random;
uniform vec2 u_resolution;
uniform sampler2DRect u_tex0;
uniform float u_colorFactor;
float random (vec2 st) {
return fract(sin(dot(st.xy,
vec2(20.9898,78.233)))*
43758.5453123);
}
mat2 scale(vec2 _scale){
return mat2(_scale.x,0.0,
0.0,_scale.y);
}
// 2D Noise based on Morgan McGuire @morgan3d
// https://www.shadertoy.com/view/4dS3Wd
float noise (in vec2 st) {
vec2 i = floor(st);
vec2 f = fract(st);
// Four corners in 2D of a tile
float a = random(i);
float b = random(i + vec2(1.0, 0.0));
float c = random(i + vec2(0.0, 1.0));
float d = random(i + vec2(1.0, 1.0));
// Smooth Interpolation
// Cubic Hermine Curve. Same as SmoothStep()
vec2 u = f*f*(3.0-2.0*f);
// u = smoothstep(0.,1.,f);
// Mix 4 coorners percentages
return mix(a, b, u.x) +
(c - a)* u.y * (1.0 - u.x) +
(d - b) * u.x * u.y;
}
void main()
{
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.y = 1.-st.y; // invert y to draw normally per openFrameworks
st *= u_resolution; // de-normalize coords
float timePassed = u_time;
vec4 color = vec4(st.x,st.y,0.0,0.0);
color = texture2DRect(u_tex0,st);
vec2 translate =scale( vec2(sin(u_time)) ) * st;
st += translate*0;
vec2 ipos = floor(st);
vec2 fpos = fract(st);
//move ipos to 30
vec2 pos = vec2(st* random(fpos));
// Use the noise function
float n = noise(pos);
//color.r = gl_FragCoord.y -u_resolution.y / tan(gl_FragCoord.y -u_time)*1;
//color.g = gl_FragCoord.y +u_resolution.y -cos(gl_FragCoord.y +u_time)*100;
//color.b = gl_FragCoord.x +u_resolution.y -sin(gl_FragCoord.x +u_time)*400;
//outputColor = vec4(color.r,color.g,color.b,1);
float grey =0.21 *color.r +0.91 *color.g +0.07 * color.b;
outputColor = vec4(color.r * u_colorFactor + grey * (1.0 - u_colorFactor),color.g * u_colorFactor + grey * (1.0 - u_colorFactor),color.b * u_colorFactor + grey * (1.0 - u_colorFactor),1.0);