Commit 70659675 authored by Lky's avatar Lky

setup basic luma matte

parent 11c56e00
......@@ -14,6 +14,9 @@ uniform float opBC_ch1;
uniform float opBC_ch2;
uniform float opBC_ch3;
uniform float key_value_threshold;
uniform int key_hue_threshold;
uniform int panel_width;
uniform int panel_height;
uniform int blendmode;
......@@ -74,6 +77,53 @@ vec3 RGBToHSL(vec3 color)
return hsl;
}
vec3 RGBToHSV(vec3 color)
{
vec3 hsv;
float fmin = min(min(color.r, color.g), color.b); // Min. value of RGB
float fmax = max(max(color.r, color.g), color.b); //Max. value of RGB
if (fmin == fmax) {
hsv.x = 0;
} else if (fmax == color.r) {
hsv.x = 60 * (0 + (color.g - color.b)/(fmax-fmin));
} else if (fmax == color.g) {
hsv.x = 60 * (2 + (color.b - color.r)/(fmax-fmin));
} else {
hsv.x = 60 * (4 + (color.r - color.g)/(fmax-fmin));
}
while (hsv.x < 0) {
hsv.x += 360;
}
if (fmax == 0) {
hsv.y = 0;
} else {
hsv.y = (fmax - fmin)/fmax;
}
hsv.z = fmax;
return hsv;
}
vec3 HSLtoHSV(vec3 hsl)
{
// rules from https://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_HSL_to_HSV
vec3 hsv;
hsv.x = hsl.x;
hsv.z = hsl.z + hsl.y * min(hsl.z, 1-hsl.z);
if (hsv.z == 0) {
hsv.y = 0;
} else {
hsv.y = 2 - 2 * hsl.z / hsv.z;
}
return hsv;
}
float HueToRGB(float f1, float f2, float hue)
{
if (hue < 0.0)
......@@ -318,6 +368,23 @@ void main()
}
// note:: CSB goes from effect to negative (if mouseX from 1 to -1).
// HUE-VALUE matte
vec3 hsv_color = RGBToHSV(color);
vec3 tmp_color = color;
if (hsv_color.x > key_hue_threshold) {
if (hsv_color.z > key_value_threshold) {
tmp_color = color;
} else {
tmp_color = vec3(0,0,0);
}
} else {
tmp_color = vec3(0,0,0);
}
color = tmp_color;
// key_value_threshold
// key_hue_threshold;
outputColor = vec4(color,1); //channel_2.r);
}
\ No newline at end of file
......@@ -47,6 +47,8 @@ void ofApp::setup()
playing_record = false;
noise_img.allocate(60, 20, OF_IMAGE_GRAYSCALE);
key_hue = 120; key_value = 0.5;
/*ofxTextureRecorder::Settings settings(main_fbo.getTexture());
settings.imageFormat = OF_IMAGE_FORMAT_JPEG;
......@@ -297,6 +299,7 @@ void ofApp::draw()
//float sin_val = opBC_ch1;// sin(actual_frame * PI / 180);
string windowName = ofToString(ofGetFrameRate()) + " - speeds: "+ ofToString(speed_ch1) + "-"+ofToString(speed_ch2) + "-"+ ofToString(speed_ch3) + " : opBC: " + "-" + ofToString(opBC_ch1) + "-" + ofToString(opBC_ch2) + "-" + ofToString(opBC_ch3) + " - blendmode::" + ofToString(blendmode);
windowName += "x_sub:"+ ofToString(x_sub)+", w_sub:" + ofToString(w_sub) + ", sx_sub:" + ofToString(sx_sub) + ".";
windowName += "key_hue = "+ ofToString(key_hue) +"; key_value = " + ofToString(key_value);
ofSetWindowTitle(windowName);
ofScale(1); // 3 is better
......@@ -309,7 +312,6 @@ void ofApp::draw()
ofClear(0, 0, 0);
shader.begin();
/*shader.setUniform1f("mouseX", mousePositionX);
shader.setUniform1f("mouseY", mousePositionY);*/
......@@ -327,6 +329,9 @@ void ofApp::draw()
shader.setUniform1f("opBC_ch1", opBC_ch1);
shader.setUniform1f("opBC_ch2", opBC_ch2);
shader.setUniform1f("opBC_ch3", opBC_ch3);
shader.setUniform1i("key_hue_threshold", key_hue);
shader.setUniform1f("key_value_threshold", key_value);
shader.setUniform1i("panel_height", panelHeight);
shader.setUniform1i("panel_width", panelWidth);
......@@ -419,6 +424,7 @@ void ofApp::keyPressed(int key){
speed_ch2 += 0.2;
hap_ch2.setSpeed(speed_ch2);
break;
case 's':
speed_ch2 -= 0.2;
hap_ch2.setSpeed(speed_ch2);
......@@ -464,6 +470,20 @@ void ofApp::keyPressed(int key){
opBC_ch3 -= 0.1;
break;
case 'h':
key_hue += 10;
break;
case 'H':
key_hue -= 10;
break;
case 'v':
key_value += .1;
break;
case 'V':
key_value -= .1;
break;
//key_hue
case '[':
x_sub -= 10;
break;
......
......@@ -63,6 +63,8 @@ public:
int testValue;
ofShader shader;
int key_hue; float key_value;
// ARDUINO SETUP
ofArduino ard;
......
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