#pragma once

#include "ofMain.h"
#include "ofxFXObject.h"

class ofxVMixer : public ofxFXObject {
public:

	ofxVMixer() {
		passes = 1;
		internalFormat = GL_RGBA32F;
		fragmentShader = STRINGIFY(
			uniform float     time;           // shader playback time (in seconds)
		uniform vec3      mouse;
		uniform vec2      resolution;           // viewport resolution (in pixels)
		uniform sampler2D tex0;          // BufA
		uniform sampler2D tex1;          // Front2
		uniform float mixrate;


		void main()
		{
			vec2 uv = gl_FragCoord.xy / resolution.xy;
			vec2 uv2 = gl_FragCoord.xy / resolution.xy;
			vec3 c = vec3(0.0);
			float mix1 = 0.5;
			float mix2 = 1.0;

			c = (texture2D(tex0, uv)*(mix1)).rgb*1.1 + (texture2D(tex1, uv2)*(mix2)).rgb*abs(cos(time*0.2)*0.9);
			c -= (texture2D(tex1, uv2)*(mix2*0.9)).rgb*abs(cos(time*0.2)*0.2);

			c -= clamp(((texture2D(tex1,uv)*(mix1)).rgb * (texture2D(tex1, uv)*(mix2)).rgb)*0.001*time,vec3(0.0),vec3(1.1));

			gl_FragColor = vec4(c, 1.0);
		});

	};
	void update(float time, float eflip) {

		shader.setUniform1f("time", time);
		shader.setUniform1f("mixrate", eflip);
		shader.setUniform2f("resolution", (float)width, (float)height);
		shader.setUniform2f("mouse", (float)ofGetMouseX() / width, (float)ofGetMouseY() / height);
	};

};

