Commit 1320886b authored by Lky's avatar Lky

set up shaders for opacity and blending modes. Configure keyboard for basic uses 3x3 channels.

parent 56031323
......@@ -4,10 +4,16 @@
uniform sampler2DRect tex1;
uniform sampler2DRect tex2;
uniform sampler2DRect tex3;
uniform sampler2DRect tex4;
uniform float main_opacity;
uniform float opBC_ch1;
uniform float opBC_ch2;
uniform float opBC_ch3;
uniform float sin_value;
uniform int panel_width;
uniform int panel_height;
uniform int blendmode;
in vec2 brightContrast;
in vec2 texCoordVarying;
......@@ -127,28 +133,172 @@ vec3 ContrastSaturationBrightness(vec3 color, float con, float sat, float brt)
return conColor;
}
vec3 BlendColor(vec3 layer_1, vec3 layer_2, int blendmode) {
vec3 result;
switch (blendmode) {
case 0:
// 0 - basic superimposition
for (int i = 0; i < 3; ++i) {
result[i] = (layer_1[i] + layer_2[i]) / 2;
}
break;
case 1:
// 1 - multiply a * b
for (int i = 0; i < 3; ++i) {
result[i] = layer_1[i] * layer_2[i];
}
break;
case 2:
// 2 - screen 1 - (1 - a) * (1 - b)
for (int i = 0; i < 3; ++i) {
result[i] = 1 - (1 - layer_1[i]) * (1 - layer_2[i]);
}
break;
case 3:
// 3 - darken min(a, b)
for (int i = 0; i < 3; ++i) {
result[i] = min(layer_1[i], layer_2[i]);
}
break;
case 4:
// 4 - lighten max(a, b)
for (int i = 0; i < 3; ++i) {
result[i] = max(layer_1[i], layer_2[i]);
}
break;
case 5:
// 5 - difference abs(a - b)
for (int i = 0; i < 3; ++i) {
result[i] = abs(layer_1[i] - layer_2[i]);
}
break;
case 6:
// 6 - negation 1 - abs(1 - a - b)
for (int i = 0; i < 3; ++i) {
result[i] = 1 - abs(1 - layer_1[i] - layer_2[i]);
}
break;
case 7:
// 7 - exclusion a + b - 2 * a * b
for (int i = 0; i < 3; ++i) {
result[i] = layer_1[i] + layer_2[i] - 2 * layer_1[i] * layer_2[i];
}
break;
case 8:
// 8 - overlay a < .5 ? (2 * a * b) : (1 - 2 * (1 - a) * (1 - b))
for (int i = 0; i < 3; ++i) {
float a = layer_1[i];
float b = layer_2[i];
result[i] = a < .5 ? (2 * a * b) : (1 - 2 * (1 - a) * (1 - b));
}
break;
case 9:
// 9 - hard light b < .5 ? (2 * a * b) : (1 - 2 * (1 - a) * (1 - b))
for (int i = 0; i < 3; ++i) {
float a = layer_1[i];
float b = layer_2[i];
result[i] = b < .5 ? (2 * a * b) : (1 - 2 * (1 - a) * (1 - b));
}
break;
case 10:
// 10 - soft light b < .5 ? (2 * a * b + a * a * (1 - 2 * b)) : (sqrt(a) * (2 * b - 1) + (2 * a) * (1 - b))
for (int i = 0; i < 3; ++i) {
float a = layer_1[i];
float b = layer_2[i];
result[i] = b < .5 ? (2 * a * b + a * a * (1 - 2 * b)) : (sqrt(a) * (2 * b - 1) + (2 * a) * (1 - b));
}
break;
case 11:
// 11 - dodge a / (1 - b)
for (int i = 0; i < 3; ++i) {
float a = layer_1[i];
float b = layer_2[i];
result[i] = a / (1 - b);
}
break;
case 12:
// 12 - burn 1 - (1 - a) / b
for (int i = 0; i < 3; ++i) {
float a = layer_1[i];
float b = layer_2[i];
result[i] = 1 - (1 - a) / b;
}
break;
}
return result;
}
void main()
{
vec4 channel_1 = texture2DRect(tex1, texCoordVarying);
vec4 channel_2 = texture2DRect(tex2, vec2(texCoordVarying.x,texCoordVarying.y));
vec4 channel_3 = texture2DRect(tex3, texCoordVarying);
vec4 channel_4 = texture2DRect(tex4, texCoordVarying);
float sin_val = sin_value;
vec3 mixed_colors = mix(channel_1.rgb,channel_3.rgb,.5);
//mixed_colors = mix(mixed_colors,channel_3.rgb,.5);
float sin_val = opBC_ch1;
vec3 color;
vec3 color_layer_1, color_layer_2;
if (texCoordVarying.y/panel_height < 0.3) {
color = ContrastSaturationBrightness(channel_1.rgb,1,1,1);//vec3(channel_1.r,channel_1.g,channel_1.b),0.5,0,1);
} else if (texCoordVarying.y/panel_height < 0.6) {
color = ContrastSaturationBrightness(channel_2.rgb,1,1,2);
} else {
color = ContrastSaturationBrightness(channel_3.rgb,1,1,1);
color_layer_1 = ContrastSaturationBrightness(channel_1.rgb,1,1,1);
color_layer_1 = mix(vec3(0,0,0),color_layer_1,main_opacity);
color_layer_2 = ContrastSaturationBrightness(channel_4.rgb,(opBC_ch1/2)+1,1,opBC_ch1/2);
color_layer_2 = mix(vec3(0,0,0),color_layer_1,opBC_ch1);
}
else if (texCoordVarying.y/panel_height < 0.6) {
color_layer_1 = ContrastSaturationBrightness(channel_2.rgb,1,1,1);
color_layer_1 = mix(vec3(0,0,0),color_layer_1,main_opacity);
color_layer_2 = ContrastSaturationBrightness(channel_4.rgb,(opBC_ch2/2)+1,1,opBC_ch2/2);
color_layer_2 = mix(vec3(0,0,0),color_layer_1,opBC_ch2);
}
else {
color_layer_1 = ContrastSaturationBrightness(channel_3.rgb,1,1,1);
color_layer_1 = mix(vec3(0,0,0),color_layer_1,main_opacity);
color_layer_2 = ContrastSaturationBrightness(channel_4.rgb,(opBC_ch3/2)+1,1,opBC_ch3/2);
color_layer_2 = mix(vec3(0,0,0),color_layer_1,opBC_ch3);
}
/*
1 - multiply a * b
2 - screen 1 - (1 - a) * (1 - b)
3 - darken min(a, b)
4 - lighten max(a, b)
5 - difference abs(a - b)
6 - negation 1 - abs(1 - a - b)
7 - exclusion a + b - 2 * a * b
8 - overlay a < .5 ? (2 * a * b) : (1 - 2 * (1 - a) * (1 - b))
9 - hard light b < .5 ? (2 * a * b) : (1 - 2 * (1 - a) * (1 - b))
10 - soft light b < .5 ? (2 * a * b + a * a * (1 - 2 * b)) : (sqrt(a) * (2 * b - 1) + (2 * a) * (1 - b))
11 - dodge a / (1 - b)
12 - burn 1 - (1 - a) / b
*/
color = BlendColor(color_layer_1,color_layer_2,blendmode);
//color = mix(vec3(1,0,0),vec3(0,0,1),sin_val);
// note:: CSB goes from effect to negative (if mouseX from 1 to -1).
outputColor = vec4(color,1); //channel_2.r);
......
This diff is collapsed.
......@@ -35,8 +35,9 @@ public:
int actual_frame;
vector<string> video_names;
float potar_1, potar_2, potar_4, potar_0, potar_10, potar_11;
float potar_0, potar_1, potar_2, potar_4, potar_10, potar_11, potar_12, potar_14;
int opacity_1, opacity_2, opacity_3;
int blendmode;
ofTexture videoTexture;
int w, h;
int main_w, main_h;
......@@ -47,7 +48,10 @@ public:
ofPixels pixels;
unsigned char * gray;
ofFbo main_fbo;
ofFbo fbo_ch1, fbo_ch2, fbo_ch3;
ofFbo fbo_ch1, fbo_ch2, fbo_ch3, ofFbo_ch4;
ofFbo fbo_background;
ofImage background_image;
bool recording, playing_record;
int record_actual_frame;
vector<int> recorded_sequence;
......@@ -84,6 +88,8 @@ public:
// 3-Panels Masks
int panelWidth, panelHeight;
float speed_ch1, speed_ch2, speed_ch3;
float main_opacity;
float opBC_ch1, opBC_ch2, opBC_ch3, extension_3channel;
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment